namedhao 发表于 2015-8-30 08:22:01

PHP复制文件夹及下面所有文件

1 function xCopy($source, $destination, $child){   
2   //用法:   
3   // xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录   
4   // xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录   
5   //参数说明:   
6   // $source:源目录名   
7   // $destination:目的目录名   
8   // $child:复制时,是不是包含的子目录   
9
10
11   if(!is_dir($source)){   
12     echo("Error:the $source is not a direction!");   
13     return 0;   
14   }   
15
16
17   if(!is_dir($destination)){   
18     mkdir($destination,0777);   
19   }   
20
21   $handle=dir($source);   
22   while($entry=$handle->read()) {   
23     if(($entry!=".")&&($entry!="..")){   
24       if(is_dir($source."/".$entry)){   
25         if($child)   
26         xCopy($source."/".$entry,$destination."/".$entry,$child);   
27       }   
28       else{   
29         copy($source."/".$entry,$destination."/".$entry);   
30       }   
31     }   
32   }   
33
34   return 1;   
35 }
36
37 ?>
  
页: [1]
查看完整版本: PHP复制文件夹及下面所有文件