dongzhong5756 2012-10-28 18:45
浏览 30
已采纳

用其中的文件删除目录[重复]

Possible Duplicate:
PHP: delete directory with files in it?

If i've some files inside the following path

mysite.com/install

and i've created file named as "die.php" outside /install/ where its path mysite.com/die.php once i executed it, it should delete install folder with all its files inside.

I've added to die.php the following code

<?PHP rmdir('install');?>

but it only delete /install/ folder when it is empty ! and if it have files it gives error Directory not empty in mysite.com/install

so any idea how to do it.

  • 写回答

2条回答 默认 最新

  • duan5731 2012-10-28 18:50
    关注

    This should work

    <?php
     function rrmdir($dir) {
       if (is_dir($dir)) {
         $objects = scandir($dir);
         foreach ($objects as $object) {
           if ($object != "." && $object != "..") {
             if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
           }
         }
         reset($objects);
         rmdir($dir);
       }
     }
    ?>
    

    I found it on the php site. This seems to be a common issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题