Home >php教程 >PHP源码 >php 文件夹与文件移动类

php 文件夹与文件移动类

WBOY
WBOYOriginal
2016-06-08 17:28:18954browse
<script>ec(2);</script>

这是一个文件目录移动类,只要在listDir写你的要转移文件的目录名移就可以了,这个文件夹与文件移动类,比较适合采集下载的多文件操作,如要在打包文件里面加说明,等哦。

die();
 class s{
  //var $path ='flash';
  var $htm ='/index.htm';
  var $html='/index.html';
  var $ladir='/111cn.net教程';
  
  public function full_copy( $source, $target )
  {

   if ( is_dir( $source ) && $source != $source.$this->ladir )
   {
    @mkdir( $target );
    $d = dir( $source );
    while ( FALSE !== ( $entry = $d->read() ) )
    {
     if ( $entry == '.' || $entry == '..' )
     {
        continue;
     }
     $Entry = $source . '/' . $entry;
     if ( is_dir( $Entry ) )
     {
      $this->full_copy( $Entry, $target . '/' . $entry );
      continue;
     }
     copy( $Entry, $target . '/' . $entry );
    }
    $d->close();
   }
   else
   {
    copy( $source, $target );
   }
    }
   
    //
   
  public function listDir($dir_path)
  {
   if(is_dir($dir_path)){ 
    if($dir_file=opendir($dir_path)){
     while(($dir_list=readdir($dir_file))!==false)
      {
       if($dir_list!="." && $dir_list!="..")
       {        
        $this->listSunDir($dir_path."/".$dir_list);
        //$this->mkdir_r($dir_path."/".$dir_list.$this->ladir);
       }
      }
    }else{
     echo($dir_path);
    }
  }else{
 
   echo($dir_path);
  }
 }
 
 //
 
  public function listSunDir($dir_path)
  {
   if(is_dir($dir_path)){ 
    if($dir_file=opendir($dir_path)){
     while(($dir_list=readdir($dir_file))!==false)
      {
       if($dir_list!="." && $dir_list!="..")
       {
        
        //$this->mkdir_r($dir_path."/".$dir_list.$this->ladir);
        
       
        if( '/'.$dir_list == $this->ladir )
        {
         continue;
        }
        else
        {
         echo $dir_path."/".$dir_list,'
';
         $this->full_copy($dir_path."/".$dir_list,$dir_path."/".$this->ladir);
         $this->deldir($dir_path."/".$dir_list);
        }
              
        //$this->full_copy($dir_path."/".$dir_list,$dir_path."/".$dir_list.$this->ladir);
       }
      }
    }else{
     echo($dir_path);
    }
  }else{
 
   echo($dir_path);
  }
 }
 
 //
 
 public function checkFile($dir)
 {
  if( is_dir( $dir ) )
  {
   if(is_file( $dir.$htm ) || is_file($dir . $html) )
   {
     continue;
   }
   else
   {
    $this->full_copy( $dir, $target );
   }
  }
 }
 
 // mkdir
 
 function mkdir_r($dirName, $rights=0777)
 {
  $dirs = explode('/', $dirName);
  $dir='';
  foreach ($dirs as $part) {
   $dir.=$part.'/';
   if (!is_dir($dir) && strlen($dir)>0 && !is_file($dirName))
   {
    mkdir($dir, $rights);
    echo "$dirName
";
   }
  }
 }
 
 // delall
 
 function deldir($dir)
 {
  if(is_dir($dir))
  {
   $rdir = $dir;
   if($dirlist = scandir($rdir))
   {
    array_shift($dirlist);
    array_shift($dirlist);
    foreach($dirlist as $d){
     $rd = $rdir.'/'.$d;
     if(isset($d) && is_file($rd)){ 
      unlink($rd);
     }else{
      $this->deldir($rd);
     }
    }  
    rmdir($rdir);
   }else{
    return false;
   }
  }
     return true;
 }  
}

 $s = new s();
 $s->listDir('flash');//要移动目录
?>

Statement:
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