zoukankan      html  css  js  c++  java
  • 【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 );
  • 相关阅读:
    Linux rcp命令详解
    Linux patch命令详解
    Linux paste命令详解
    linux od命令详解
    linux mv命令详解
    Linux more命令详解
    Linux mktemp命令
    MySQL状态变量详解
    mysql性能分析show profile/show profiles
    MySQL执行计划
  • 原文地址:https://www.cnblogs.com/Horsonce/p/7889364.html
Copyright © 2011-2022 走看看