简体   繁体   English

使用 php 脚本从主机中删除所有 .htaccess 文件

[英]Delete all .htaccess files form host using php script

i need to delete all .htaccess files from the host but unfortunately a terminal is not available so may be it can be done using a php script.我需要从主机中删除所有 .htaccess 文件,但不幸的是终端不可用,所以可能可以使用 php 脚本来完成。 example: host path is home/name/public_html/ and inside the public_html folder there are other folders and subfolders and using a php script i was able to output all files path and count all .htaccess files (around 9000)... Please anyone can help to delete all these files as going folder by folder(subfolder) will take weeks as there are more than 8k folders/subfolders.示例:主机路径是 home/name/public_html/ 并且在 public_html 文件夹内还有其他文件夹和子文件夹,并且使用 php 脚本我能够输出所有文件路径并计算所有 .htaccess 文件(大约 9000 个)...请任何人可以帮助删除所有这些文件,因为文件夹(子文件夹)将需要数周时间,因为有超过 8k 个文件夹/子文件夹。

Thanks in advance提前致谢

thanks to @LawrenceCherone for the indication on RecursiveDirectoryIterator感谢@LawrenceCherone 对RecursiveDirectoryIterator的指示

Got an example there and with few changes i was able to figure it out Here is the script in case anyone will need it on future:那里有一个例子,几乎没有什么改变我能够弄清楚这是脚本,以防将来有人需要它:

$dir = new RecursiveDirectoryIterator(getcwd());
$files = new RecursiveIteratorIterator($dir);

foreach($files as $file){
    $name_of_file = $file->getFileName();
    $path_of_file = $file->getPath()."/".$file->getFileName(); 
    //need to concatenate "/" otherwise it shows all attached (path and file name)
    if ($name_of_file == ".htaccess") {
        //echo $path_of_file . "<br />";
        unlink($path_of_file);
    }
}

Thanks to all for the help.感谢大家的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM