怎么自动生成htm文件
为安全隐患问题,
想在上传图片的同时,在图片的目录自动生成个空白的htm文件。
图片目录是根据时间定义的 所以 目录有点多。
php 怎么实现这个?
回复讨论(解决方案)
like this
if (!file_exists('index.html')){ file_put_contents('index.html', 'hello world');}
touch('index.html')
ecmall的:
function ecm_mkdir($absolute_path, $mode = 0777){ if (is_dir($absolute_path)) { return true; } $root_path = ROOT_PATH; $relative_path = str_replace($root_path, '', $absolute_path); $each_path = explode('/', $relative_path); $cur_path = $root_path; // 当前循环处理的路径 foreach ($each_path as $path) { if ($path) { $cur_path = $cur_path . '/' . $path; if (!is_dir($cur_path)) { if (@mkdir($cur_path, $mode)) { fclose(fopen($cur_path . '/index.htm', 'w')); } else { return false; } } } } return true;}
like this
if (!file_exists('index.html')){ file_put_contents('index.html', 'hello world');}
创建位置怎么设置
应该设置成 图片所有路径下 都自动生成个html文件
比如图片地址是 file/2015/05/20/100.gif
那应该在file目录 2015目录 05目录和20目录下 都生成个空白的html文件 不知道怎么实现啊
$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));}
$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));}
你自己再改一下,这个递归没有判断退出条件
$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));}
只在 /file/2015/05/20/生成文件
我竟然写了3条 实现了 现在问题是 怎么合并代码
$file_path = 'file/';
$tm_path = 'file/'.$Y.'/'; // file/2015
$path = 'file/'.$Y.'/'.$M.'/'; // file/2015/05
file_put_contents($path . '/index.html', '111');
file_put_contents($tm_path . '/index.html', '111');
file_put_contents($file_path . '/index.html', '111');
想在上传图片的同时,在图片的目录自动生成个空白的htm文件
显然图片文件已经保存了,假定保存图片是的路径在 $img_path 中
那么只需
file_put_contents(dirname($img_path) . '/index.html', '');
如果在保存图片时不能确定相应目录是否存在,那么这样就可以了
@mkdir(dirname($img_path), 0666, true);
想在上传图片的同时,在图片的目录自动生成个空白的htm文件
显然图片文件已经保存了,假定保存图片是的路径在 $img_path 中
那么只需
file_put_contents(dirname($img_path) . '/index.html', '');
如果在保存图片时不能确定相应目录是否存在,那么这样就可以了
@mkdir(dirname($img_path), 0666, true);
所有路径的目录都要有html文件

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸
