Home > php教程 > php手册 > PHP删除整个文件夹和移动整个文件夹

PHP删除整个文件夹和移动整个文件夹

WBOY
Release: 2016-06-21 09:06:30
Original
1075 people have browsed it

 // ========== doDelDir函数 START ==========
        function doDelDir($dir)
        {
            $dh=opendir($dir);
            while ($file=readdir($dh))
            {
                if($file!="." && $file!="..")
                {
                    $fullpath=$dir."/".$file;
                    if(!is_dir($fullpath))
                    {
                        unlink($fullpath);
                    }
                    else
                    {
                        $this->doDelDir($fullpath);
                    }
                }
            }
            closedir($dh);
            if (rmdir($dir))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
  // ========== doDelDir函数 END ==========

  // ========== doMoveDir函数 START ==========
  function doMoveDir($source,$target)
  {
   if(is_dir($source))
   {
    $dest_name=basename($source);
    if(!mkdir($target.$dest_name))
    {
     return false;
    }
    $d=dir($source);
    while(($entry=$d->read())!==false)
    {
     if(is_dir($source.$entry))
     {
      if($entry=="."||$entry=="..")
      {
       continue;
      }
      else
      {
       $this->doMoveDir("$source$entry\\","$target$dest_name\\");
      }
     }
     else
     {
      if(!copy("$source$entry","$target$dest_name\\$entry"))
      {
       return false;
      }
     }                 
    }         
   }
   else
   {
    if(!copy("$source$entry","$target$dest_name\\"))
    {
     return false;
    }         
   }         
   return true; 
  }
  // ========== doMoveDir函数 END ==========




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template