使用PHP脚本删除所有.htaccess文件形式的主机

发布于 2025-02-02 05:51:34 字数 233 浏览 4 评论 0原文

我需要从主机删除所有.htaccess文件,但不幸的是,终端不可用,因此可以使用PHP脚本完成。 示例:主机路径是home/name/public_html/,在public_html文件夹中,还有其他文件夹和子文件夹,并且使用php脚本,我能够输出所有文件路径并计数所有.htaccess文件(左右9000)... 请任何人都可以帮助删除所有这些文件,因为文件夹(子文件夹)将需要数周的时间,因为有超过8K的文件夹/子文件夹。

提前致谢

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.
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.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2025-02-09 05:51:34

感谢@lawrencecherone在 recursivedirectoryIterator

与示例获得了一个示例我几乎无法弄清楚的更改
这是脚本,以防将来任何人都需要它:

$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 @LawrenceCherone for the indication on 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文