【问题标题】:Cakephp copy whole app directory and subdirectories?Cakephp 复制整个应用程序目录和子目录?
【发布时间】:2014-12-22 09:57:30
【问题描述】:

您好,我是一名新出生的程序员,正在尝试构建一个 Cakephp 系统,允许用户注册然后为他们创建一个目录并将我的预构建系统免费复制到他们的目录中。但是我正在将我的应用程序目录复制到他们的目录中。我尝试使用递归复制功能,但它只复制文件而不是所有子目录。

请帮我解决这个问题。

编辑: 抱歉没有附上代码 代码如下:

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

【问题讨论】:

标签: php cakephp directory


【解决方案1】:

Try something like this:

<?php
foreach (
 $iterator = new \RecursiveIteratorIterator(
  new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
  \RecursiveIteratorIterator::SELF_FIRST) as $item
) {
  if ($item->isDir()) {
    mkdir($dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  } else {
    copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  }
}
?>

If you want your code snippet to be looked over please post it

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 2010-09-21
    • 2014-11-22
    相关资源
    最近更新 更多