2012-10-26 66 views
0

我有一些问题,下面的函数是假设复制整个目录及其内容 - opendir行返回无法打开每一次,我不知道为什么。该源确实存在,并且拥有755个权限(也尝试了757个权限,但仍然没有运气!)。PHP copydir功能问题

任何人都可以提出任何建议吗?

function copydir($source,$destination) 
{ 
    if(!is_dir($destination)) 
    { 
     $oldumask = umask(0); 
     mkdir($destination, 0757); // so you get the sticky bit set 
     umask($oldumask); 
    } 

    $dir_handle = @opendir($source) or die("Unable to open"); 
    while ($file = readdir($dir_handle)) 
    { 
     if($file!="." && $file!=".." && !is_dir("$source/$file")) //if it is file 
     { 
      copy("$source/$file","$destination/$file"); 
     } 

     if($file!="." && $file!=".." && is_dir("$source/$file")) //if it is folder 
     { 
      copydir("$source/$file","$destination/$file"); 
     } 
    } 
    closedir($dir_handle); 
} 
+1

为什么在php中这样做?操作系统是这样做的:'exec(cp source dest);' – JvdBerg

+1

它是一个基于php的服务器,我没有访问权限,除非通过ftp,所以真的需要一个php解决方案 – Jason

+6

删除'@'让你看到实际错误消息 –

回答

0

在什么平台上运行这个?我只是在Windows上试了一下,效果非常好。