Home  >  Article  >  Backend Development  >  如何自动生成htm文件

如何自动生成htm文件

WBOY
WBOYOriginal
2016-06-13 12:20:191318browse

怎么自动生成htm文件
为安全隐患问题,

想在上传图片的同时,在图片的目录自动生成个空白的htm文件。

图片目录是根据时间定义的 所以 目录有点多。

php 怎么实现这个?
------解决思路----------------------
like this

<br />if (!file_exists('index.html')){<br />    file_put_contents('index.html', 'hello world');<br />}<br />

------解决思路----------------------
<br />$imgUrl = '/file/2015/05/20/100.gif';<br />$path = dirname($imgUrl);<br />createHtml($path);<br />function createHtml($path)<br />{<br />	if (!file_exists($path . '/index.html')){<br />	    file_put_contents($path . '/index.html', 'hello world');<br />	}<br />	createHtml(dirname($path));<br />}<br />

------解决思路----------------------
想在上传图片的同时,在图片的目录自动生成个空白的htm文件
显然图片文件已经保存了,假定保存图片是的路径在 $img_path 中
那么只需
file_put_contents(dirname($img_path) . '/index.html', '');

如果在保存图片时不能确定相应目录是否存在,那么这样就可以了
@mkdir(dirname($img_path), 0666, true);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn