>  기사  >  백엔드 개발  >  如何自动生成htm文件

如何自动生成htm文件

WBOY
WBOY원래의
2016-06-13 12:20:191319검색

怎么自动生成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);

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.