//////////////////////////////////////////////////////////
//copy a direction’s all files to another direction 
function xCopy($source, $destination, $child){ 
//用法: 
// xCopy("feiy","feiy2",1):拷贝feiy下的文件到 feiy2,包括子目录 
// xCopy("feiy","feiy2",0):拷贝feiy下的文件到 feiy2,不包括子目录 
//参数说明: 
// $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; 
}

解决方案 »

  1.   

    再请问为什么不可连继建下一级目录呢?
    $path="/lee/lee1";
    $path1="/lee/lee1/lee2";
    if(mkdir($path,0777))
    {
    echo ".......ok.....";
     if(mkdir($path1,0777))
      {
      echo ".....2 ok....";
      }
    }
    else
    {
    echo "...not...";
    }
      

  2.   

    无限级目录复制代码(站长原创)
    无限级目录复制,站长原创,虽只写了短短几分钟,但还是挺有用的
    <?
    //本程序由wm_chief原创,如要转载,请注明作者与来源(http://www.phome.net)
    $o_path="admin";//源目录
    $n_path="n_admin";//新目录
    class copy_path
    {
    function wm_chief_copypath($o_path,$n_path)
    {$hand=opendir($o_path);
    if(!file_exists($n_path))//目标目录不存在则建立
    {$this->wm_chief_createpath($n_path);}
    $i=0;
    while($file=readdir($hand))
    {$i++;
    if($i==1||$i==2)
    {continue;}
    if(!(strchr($file,".")))
    {
    $o_s_path=$o_path."/".$file;
    $n_s_path=$n_path."/".$file;
    $this->wm_chief_copypath($o_s_path,$n_s_path);
    }
    else
    {
    $o_file=$o_path."/".$file;
    $n_file=$n_path."/".$file;
    $this->wm_chief_copyfile($o_file,$n_file);
    }
    }
    closedir($hand);
    return true;
    }
    function wm_chief_copyfile($o_file,$n_file)
    {
    copy($o_file,$n_file);
    }
    function wm_chief_createpath($n_path)
    {
    mkdir($n_path,0777);
    }
    }
    $wm_chief=new copy_path();
    $wm_chief_ok=$wm_chief->wm_chief_copypath($o_path,$n_path);
    if($wm_chief_ok)
    {
    echo"复制完毕";
    }
    //本程序由wm_chief原创,如要转载,请注明作者与来源(http://www.phome.net)
    ?>
      

  3.   

    windows:
    exec("xcopy32/s src_dir di_dir",$str,$var);
    linux:
    exec("cp -r ........
    如果需要复杂交互操作可以使用管道
    popen();
    或者更加强大的
    proc_open();//php4.3.0