php - 从我的 public_html 文件夹中可用的所有文件夹中删除具有特定名称的文件
问题描述
我的服务器根目录及其文件夹中散布着一个恶意文件。是否有任何方法/ php 脚本可以使用它一次从所有文件夹中删除所有 em。
解决方案
function deleteFileFromDir($dir, $filename){
$ffs = scandir($dir);
unset($ffs[array_search('.', $ffs, true)]);
unset($ffs[array_search('..', $ffs, true)]);
foreach($ffs as $ff){
if(is_dir($dir.'/'.$ff)){
deleteFileFromDir($dir.'/'.$ff, $filename);
} else {
if( $ff == $filename ){
echo "found ".$dir.'/'.$ff.'<br>';
unlink($dir.'/'.$ff);
}
}
}
}
$search_dir_path = '.'; // The same folder as the file location
$search_file = 'some_file_to_delete.txt';
deleteFileFromDir($search_dir_path, $search_file);
只需根据需要更改$search_dir_path
和$search_file
变量。
推荐阅读
- cron - Crontab 如何禁用电子邮件
- python - 即使使用正确的语法和正确的 poutput,python 3.0 中的 eof
- kotlin - Kotlin-multiplatform:ShadowJar gradle 插件创建空 jar
- python - IndexError:Pygame 中的列表索引超出范围和回溯错误
- android - 处理项目 ViewHolder 的滑动手势侦听器
- flutter - 切换 .resume 和 .pause 时更改订阅图标按钮的颜色。为什么这不起作用?
- python - 在 python 中,使用 join() 关键字的字数/字符数是否有最大限制?
- r - 可视化 lme 的交叉随机效应
- flask - Flask:从 SQLAlchemy 查询继承的类会在两个相似的上下文中带来不同的结果
- node.js - 使用for循环在sails js中上传文件