PHP文件夹复制的函数
PHP #文件夹复制 #函数2012-10-30 12:59
01 | <?php |
02 |
03 | /** |
04 | * 复制文件夹 |
05 | eg:将D:/wwwroot/下面wordpress复制到 |
06 | D:/wwwroot/www/explorer/0000/del/1/ |
07 | 末尾都不需要加斜杠,复制到地址如果不加源文件夹名, |
08 | 就会将wordpress下面文件复制到D:/wwwroot/www/explorer/0000/del/1/下面 |
09 | * $from = 'D:/wwwroot/wordpress'; |
10 | * $to = 'D:/wwwroot/www/explorer/0000/del/1/wordpress'; |
11 | * |
12 | * @link http://yige.org/php/ |
13 | */ |
14 |
15 | function copy_dir( $source , $dest ){ |
16 | $result = false; |
17 | if ( is_file ( $source )) { |
18 | if ( $dest [ strlen ( $dest )-1] == '/' ) { |
19 | $__dest = $dest . "/" . basename ( $source ); |
20 | } else { |
21 | $__dest = $dest ; |
22 | } |
23 | $result = @ copy ( $source , $__dest ); |
24 | //echo iconv( $config['app_charset'],$config['system_charset'], $source); |
25 | @ chmod ( $__dest , 0755); |
26 | } elseif ( is_dir ( $source )) { |
27 | if ( $dest [ strlen ( $dest )-1] == '/' ) { |
28 | $dest = $dest . basename ( $source ); |
29 | @ mkdir ( $dest ); |
30 | @ chmod ( $dest , 0755); |
31 | } else { |
32 | @ mkdir ( $dest , 0755); |
33 | @ chmod ( $dest , 0755); |
34 | } |
35 | $dirHandle = opendir( $source ); |
36 | while ( $file = readdir( $dirHandle )) { |
37 | if ( $file != "." && $file != ".." ) { |
38 | if (! is_dir ( $source . "/" . $file )) { |
39 | $__dest = $dest . "/" . $file ; |
40 | } else { |
41 | $__dest = $dest . "/" . $file ; |
42 | } |
43 | $result = copy_dir( $source . "/" . $file , $__dest ); |
44 | } |
45 | } |
46 | closedir ( $dirHandle ); |
47 | } else { |
48 | $result = false; |
49 | } |
50 | return $result ; |
51 | } |
相关文章
- PHP生成缩略图的函数 2012/10/30
- php获取文件类型和文件信息 2012/10/30
- PHP将多维数组转为一维数组的函数 2012/10/30
- PHP实现的session数据库交互类 2012/10/30
- PHP获取客户端IP地址的函数 2012/10/30
- php多文件上传的三种方法 2012/10/29
- PHP支持多种编码截取中文字符串的函数 2012/10/29
- PHP用三个类概况五种设计模式 2012/10/29
- php获取文件创建时间/修改时间 2012/10/29
- PHP读写大日志文件 2012/10/29