当前位置:Gxlcms > PHP教程 > 如何自动生成htm文件

如何自动生成htm文件

时间:2021-07-01 10:21:17 帮助过:3人阅读

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

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

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

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


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

------解决思路----------------------

$imgUrl = '/file/2015/05/20/100.gif';
$path = dirname($imgUrl);
createHtml($path);
function createHtml($path)
{
if (!file_exists($path . '/index.html')){
file_put_contents($path . '/index.html', 'hello world');
}
createHtml(dirname($path));
}

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

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

人气教程排行