php加入文件夹,使用PHP在文件夹中添加文件

标签:php

我有100多个带有子文件夹的文件夹…

例:

a/b/c/d/e

f/g/h

m/n

k/l/o/p/s/z/x/

....

我想向每个文件夹(和每个子文件夹)添加一个空白文件(index.html).

我可以用PHP做到吗?如何?

解决方法:

使用shell脚本可能会更容易:

exec('

for DIR in $(find . -type d) ; do touch "$DIR/index.html" ; done

');

通过PHP的更多努力:

function scandir_tree($dir) {

$r = array("$dir");

foreach (scandir($dir) as $fn) {

if (is_dir("$dir/$fn") && ($fn[0] != ".")) {

$r = array_merge($r, scandir_tree("$dir/$fn"));

}

}

return $r;

}

foreach (scandir_tree(".") as $dir) {

touch("$dir/index.html");

}

或者说,使用单个Options -Index via .htaccess阻止使用Apache生成默认目录列表.

标签:php

来源: https://codeday.me/bug/20191208/2090683.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHPWEB产品模块增加下载文件(下载里面自带修改好的文件): 1:product\admin\product_conadd.php 页面, 这是产品新增页面 从134行起新增如下代码, 是用来上传文件的: <!--新增上传文件 开始 --> <tr> <td height="30" width="100" align="center">文件上传</td> <td height="30" valign="top"> <input id="divsuo" type="file" name="file" style="width: 499px; display: none;" class="input"> <input id="divurl" type="text" name="fileurl" style="width: 499px; display: inline;" value="http://" class="input"> <input type="radio" name="addtype" value="addurl" checked="" onclick="document.getElementById('divurl').style.display='inline';document.getElementById('divsuo').style.display='none';"> 链接网址 <input type="radio" name="addtype" value="addfile" onclick="document.getElementById('divurl').style.display='none';document.getElementById('divsuo').style.display='inline';"> 上传文件 </td> </tr> <!--新增上传文件 结束 --> 2:product\admin\product_conmod.php页面, 这是产品的修改页面 从188行起新增如下代码, 是用来上传文件的: <!--新增上传文件 开始 --> <tr> <td height="30" width="100" align="center">文件上传</td> <td height="30" valign="top"> <input id="divsuo" type="file" name="file" style="width: 499px; display: none;" class="input"> <input id="divurl" type="text" name="fileurl" style="width: 499px; display: inline;" value="<?php echo $fileurl; ?>" class="input"> <input type="radio" name="addtype" value="addurl" checked="" onclick="document.getElementById('divurl').style.display='inline';document.getElementById('divsuo').style.display='none';"> 链接网址 <input type="radio" name="addtype" value="addfile" onclick="document.getElementById('divurl').style.display='none';document.getElementById('divsuo').style.display='inline';"> 上传文件 </td> </tr> <!--新增上传文件 结束 --> 3:product\admin\post.php页面, 这是产品的获取数据用的 281行代码注释, 新增282行代码: //新增下载 $msql->query( "update {P}_product_con set \r\n\t\t\ttitle='{$title}',\r\n\t\t\tmemo='{$memo}',\r\n\t\t body='{$body}',\r\n\t\t\tcatid='{$catid}',\r\n\t\t\tcatpath='{$catpath}',\r\n\t\t\tuptime='{$uptime}',\r\n\t\t\tauthor='{$author}',\r\n\t\t\tsource='{$source}',\r\n\t\t\tproj='{$projpath}',\r\n\t\t\ttags='{$tagstr}',\r\n\t\t\tprop1='{$prop1}',\r\n\t\t\tprop2='{$prop2}',\r\n\t\t\tprop3='{$prop3}',\r\n\t\t\tprop4='{$prop4}',\r\n\t\t\tprop5='{$prop5}',\r\n\t\t\tprop6='{$prop6}',\r\n\t\t\tprop7='{$prop7}',\r\n\t\t\tprop8='{$prop8}',\r\n\t\t\tprop9='{$prop9}',\r\n\t\t\tprop10='{$prop10}',\r\n\t\t\tprop11='{$prop11}',\r\n\t\t\tprop12='{$prop12}',\r\n\t\t\tprop13='{$prop13}',\r\n\t\t\tprop14='{$prop14}',\r\n\t\t\tprop15='{$prop15}',\r\n\t\t\tprop16='{$prop16}',\r\n\t\t\tprop17='{$prop17}',\r\n\t\t\tprop18='{$prop18}',\r\n\t\t\tprop19='{$prop19}',\r\n\t\t\tprop20='{$prop20}', \r\n\t\t\tfileurl='{$fileurl}'\r\n\t\t\twhere id='{$id}'\r\n\t\t" ); 454行代码注释, 新增457行代码: //新增下载 $msql->query( "insert into {P}_product_con set\r\n\t\tcatid='{$catid}',\r\n\t\tcatpath='{$catpath}',\r\n\t\ttitle='{$title}',\r\n\t\tbody='{$body}',\r\n\t\tdtime='{$dtime}',\r\n\t\txuhao='0',\r\n\t\tcl='0',\r\n\t\ttj='0',\r\n\t\tiffb='1',\r\n\t\tifbold='0',\r\n\t\tifred='0',\r\n\t\ttype='gif',\r\n\t\tsrc='{$src}',\r\n\t\tuptime='{$dtime}',\r\n\t\tauthor='{$author}',\r\n\t\tsource='{$source}',\r\n\t\tmemberid='0',\r\n\t\tproj='{$projpath}',\r\n\t\ttags='{$tagstr}',\r\n\t\tsecure='0',\r\n\t\tmemo='{$memo}',\r\n\t\tprop1='{$prop1}',\r\n\t\tprop2='{$prop2}',\r\n\t\tprop3='{$prop3}',\r\n\t\tprop4='{$prop4}',\r\n\t\tprop5='{$prop5}',\r\n\t\tprop6='{$prop6}',\r\n\t\tprop7='{$prop7}',\r\n\t\tprop8='{$prop8}',\r\n\t\tprop9='{$prop9}',\r\n\t\tprop10='{$prop10}',\r\n\t\tprop11='{$prop11}',\r\n\t\tprop12='{$prop12}',\r\n\t\tprop13='{$prop13}',\r\n\t\tprop14='{$prop14}',\r\n\t\tprop15='{$prop15}',\r\n\t\tprop16='{$prop16}',\r\n\t\tprop17='{$prop17}',\r\n\t\tprop18='{$prop18}',\r\n\t\tprop19='{$prop19}',\r\n\t\tprop20='{$prop20}'\r\n\t\t,\r\n\t\t\tfileurl='{$fileurl}'\r\n\t\t" ); 4:product\admin\func\upload.inc.php页面, 新增函数: 这个函数可以修改上传文件类型 ///////////上传文件函数 function NewUploadFile($jpg,$jpg_type,$fname,$jpg_size,$path){ global $strDownNotice9,$strDownNotice11; if ($jpg_size == 0) { $arr[0]="err"; $arr[1]=$strDownNotice9; return $arr; } if (substr($fname,-4)!=".rar" && substr($fname,-4)!=".zip" && substr($fname,-4)!=".doc" && substr($fname,-4)!=".xls" && substr($fname,-4)!=".htm" && substr($fname,-5)!=".html" && substr($fname,-4)!=".gif" && substr($fname,-4)!=".jpg" && substr($fname,-4)!=".png" && substr($fname,-4)!=".chm" && substr($fname,-4)!=".txt") { $arr[0]="err"; $arr[1]=$strDownNotice11; return $arr; } $hzarr=explode(".",$fname); $num=sizeof($hzarr)-1; $UploadImage[2]=$hzarr[$num]; $timestr=time(); $hz=substr($fname,-4); $file_path = ROOTPATH.$path."/".$timestr.$hz; $UploadImage[3] = $path."/".$timestr.$hz; copy ($jpg,$file_path); chmod ($file_path,0666); $UploadImage[0]="OK"; $UploadImage[1]="OK"; return $UploadImage; } 5:product\module\ProductQuery.php页面, 新增 第138行:$fileurl='/'.$fsql->f('fileurl');//新增文件上传功能 第199行:'fileurl' => $fileurl, //新增文件上传功能

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值