PHP 复制指定文件夹内的目录及文件

发布时间:2009年01月07日      浏览次数:912 次
//用法:
//Copy_folder("源目录","目标目录",1):拷贝“源目录”下的文件到“目标目录”,包括子目录
//Copy_folder("源目录","目标目录",0):拷贝“源目录”下的文件到“目标目录”,不包括子目录
function Copy_folder($source, $destination, $child){
      if(!is_dir($source)){
            echo("Source Error!");
            return 0;
      }
      if(!is_dir($destination)){
            mkdir($destination,0777);
      }
      $handle=dir($source);
      while($entry=$handle->read()){
            if(($entry!=".")&&($entry!="..")){
                  if(is_dir($source."/".$entry)){
                         if($child) Copy_folder($source."/".$entry,$destination."/".$entry,$child);
                  }else{
                        if ( ! file_exists($destination."/".$entry) ) copy($source."/".$entry,$destination."/".$entry);
                  }
            }
      }
      return 1;
}
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!