duannaikuang1301 2014-12-27 20:07
浏览 73

php脚本删除服务器上目录中的所有文件[重复]

This question already has an answer here:

I need to delete the contents of plugin cache folder every 20 mins. I have a job planner (task planner) on my hosting. The problem is, that I need a php script, which will order to delete all the files within specified directory.

Please, help me with such one.

Thank You in advance to you all, who will answer!

</div>
  • 写回答

1条回答 默认 最新

  • doulan4371 2014-12-27 20:15
    关注

    I think you have to try something like this and let us know if any error/warning. This is a recursive function to delete all files and sub-directory within a directory.

    <?php
    function delete_directory($dirname) {
         if (is_dir($dirname))
             $dir_handle = opendir($dirname);
         if (!$dir_handle)
              return false;
         while($file = readdir($dir_handle)) {
               if ($file != "." && $file != "..") {
                    if (!is_dir($dirname."/".$file))
                         unlink($dirname."/".$file);
                    else
                         delete_directory($dirname.'/'.$file);
               }
         }
         closedir($dir_handle);
         rmdir($dirname);
         return true;
    }
    ?>
    

    For details see Here

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看