【PHP】文件转移

今天看到一段经典代码,感觉太厉害了

function recurse_copy( $src , $dst ){
     $handle = opendir( $src );
     @mkdir( $dst );
     while( false !== ( $file = readdir( $handle ) ) )
     {
         if( ( $file != '.' ) && ( $file != '..' ) )
         {
             if( is_dir( $src . '/' . $file ) )
             {
                 recurse_copy( $src . '/' . $file, $dst . '/' . $file );
             }
             else
             {
                 copy( $src . '/' . $file, $dst . '/' . $file );
             }
         }
     }
     closedir( $handle );
 }
recurse_copy( $src , $dst )
$src原有目录,$dst现有目录

2017年11月29日10:39:38 

昨天工作中遇到问题,mkdir不起作用,百思不得其解,最后找到原因:

@mkdir( $dst );中参数只有pathname,而还有两个参数至关重要,第二个参数:默认的 mode 是 0777,意味着最大访问权限,
第三个参数:recursive:
Allows the creation of nested directories specified in the pathname.中文解释:允许嵌套目录中指定的路径创造。 看到解释是不很直观明了
所以当我加上另外两个参数时,就执行成功@mkdir( $dst,0777,true );
posted on 2017-11-24 10:29  忆华灯纵博  阅读(289)  评论(0编辑  收藏  举报