• <small id='U4YFR'></small><noframes id='U4YFR'>

        <i id='U4YFR'><tr id='U4YFR'><dt id='U4YFR'><q id='U4YFR'><span id='U4YFR'><b id='U4YFR'><form id='U4YFR'><ins id='U4YFR'></ins><ul id='U4YFR'></ul><sub id='U4YFR'></sub></form><legend id='U4YFR'></legend><bdo id='U4YFR'><pre id='U4YFR'><center id='U4YFR'></center></pre></bdo></b><th id='U4YFR'></th></span></q></dt></tr></i><div id='U4YFR'><tfoot id='U4YFR'></tfoot><dl id='U4YFR'><fieldset id='U4YFR'></fieldset></dl></div>
          <bdo id='U4YFR'></bdo><ul id='U4YFR'></ul>

        <legend id='U4YFR'><style id='U4YFR'><dir id='U4YFR'><q id='U4YFR'></q></dir></style></legend>
        <tfoot id='U4YFR'></tfoot>
      1. 使用 php 删除所有文件、文件夹及其子文件夹

        时间:2023-07-15
        <i id='oHiRc'><tr id='oHiRc'><dt id='oHiRc'><q id='oHiRc'><span id='oHiRc'><b id='oHiRc'><form id='oHiRc'><ins id='oHiRc'></ins><ul id='oHiRc'></ul><sub id='oHiRc'></sub></form><legend id='oHiRc'></legend><bdo id='oHiRc'><pre id='oHiRc'><center id='oHiRc'></center></pre></bdo></b><th id='oHiRc'></th></span></q></dt></tr></i><div id='oHiRc'><tfoot id='oHiRc'></tfoot><dl id='oHiRc'><fieldset id='oHiRc'></fieldset></dl></div>

      2. <legend id='oHiRc'><style id='oHiRc'><dir id='oHiRc'><q id='oHiRc'></q></dir></style></legend>

          • <bdo id='oHiRc'></bdo><ul id='oHiRc'></ul>
            <tfoot id='oHiRc'></tfoot>

                  <tbody id='oHiRc'></tbody>

                  <small id='oHiRc'></small><noframes id='oHiRc'>

                  本文介绍了使用 php 删除所有文件、文件夹及其子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要一个脚本,它可以删除整个目录及其所有子文件夹、文件等.我尝试使用这个功能,几个月前我在互联网上找到了这个功能,但它不能完全工作.

                  I need a script which can remove a whole directory with all their subfolders, files and etc. I tried with this function which I found in internet before few months ago but it not work completely.

                  function deleteFile($dir) {
                      if(substr($dir, strlen($dir)-1, 1) != '/') { 
                          $dir .= '/'; 
                      }
                      if($handle = opendir($dir)) { 
                          while($obj = readdir($handle)) { 
                              if($obj != '.' && $obj != '..') { 
                                  if(is_dir($dir.$obj)) { 
                                      if(!deleteFile($dir.$obj)) {
                                          echo $dir.$obj."<br />";
                                          return false;
                                      }
                                  }
                                  elseif(is_file($dir.$obj)) { 
                                      if(!unlink($dir.$obj)) {
                                          echo $dir.$obj."<br />";
                                          return false;
                                      }
                                  }
                              }
                          }
                          closedir($handle); 
                          if(!@rmdir($dir)) {
                              echo $dir.'<br />';
                              return false;
                          }
                          return true;
                      }
                      return true;
                  }
                  

                  为了测试,我使用了 prestashop 的解压存档,我尝试删除解压存档的文件夹,但它不起作用.

                  For the test I use a unpacked archive of prestashop and I try to delete the folder where archive is unpacked but it doesn't work.

                  /home/***/public_html/prestashop/img/p/3/
                  /home/***/public_html/prestashop/img/p/3
                  /home/***/public_html/prestashop/img/p
                  /home/***/public_html/prestashop/img
                  

                  这些是问题文件夹.我第一次想 - 可能是文件的 chmod 有问题"但是当我测试所有文件的 chmod 权限 755(之后是 777) - 结果是一样的.

                  These are the problem folders. At the first time I think - "May is a problem with the chmod of the files" but when I test with all files chmod permission 755 (after that with 777) - the result was the same.

                  推荐答案

                  <?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);
                    }
                   }
                  ?>
                  

                  从 php.net

                  对我来说很好

                  这篇关于使用 php 删除所有文件、文件夹及其子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PHP 需要顶级目录中的文件 下一篇:目录的递归复制

                  相关文章

                    <small id='j4rkk'></small><noframes id='j4rkk'>

                  1. <tfoot id='j4rkk'></tfoot>

                  2. <legend id='j4rkk'><style id='j4rkk'><dir id='j4rkk'><q id='j4rkk'></q></dir></style></legend>
                    <i id='j4rkk'><tr id='j4rkk'><dt id='j4rkk'><q id='j4rkk'><span id='j4rkk'><b id='j4rkk'><form id='j4rkk'><ins id='j4rkk'></ins><ul id='j4rkk'></ul><sub id='j4rkk'></sub></form><legend id='j4rkk'></legend><bdo id='j4rkk'><pre id='j4rkk'><center id='j4rkk'></center></pre></bdo></b><th id='j4rkk'></th></span></q></dt></tr></i><div id='j4rkk'><tfoot id='j4rkk'></tfoot><dl id='j4rkk'><fieldset id='j4rkk'></fieldset></dl></div>
                      <bdo id='j4rkk'></bdo><ul id='j4rkk'></ul>