让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> PHP -> php递归复制目录及下面的文件

php递归复制目录及下面的文件

点击数:1191 发表时间:2015-11-20 14:45:38 作者: 来源链接:
分享到:
分享到微信

php拷贝目录及下面文件的代码与其他语言类似,都是通过递归的方式

/** 
 * $param string source:源目录名    
 * $param string destination:目的目录名    
 * $param string child:复制时,是不是包含的子目录   1包含 0不包含 
 * @return int 1成功 0失败 
 */  
function xCopy($source, $destination, $child) {  
  
    if (!is_dir($source)) {  
        echo ("Error:the $source is not a direction!");  
        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)  
                    xCopy($source .  
                    "/" . $entry, $destination . "/" . $entry, $child);  
            } else {  
                copy($source . "/" . $entry, $destination . "/" . $entry);  
            }  
        }  
    }  
  
    return 1;  
}


3
很 好
3
一 般
3
差 劲
热门新闻
相关文章
上一篇: php中xml转成array数组的代码实现
下一篇: php发送邮件类
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号