• <tfoot id='R5WG6'></tfoot>
  • <legend id='R5WG6'><style id='R5WG6'><dir id='R5WG6'><q id='R5WG6'></q></dir></style></legend>
  • <i id='R5WG6'><tr id='R5WG6'><dt id='R5WG6'><q id='R5WG6'><span id='R5WG6'><b id='R5WG6'><form id='R5WG6'><ins id='R5WG6'></ins><ul id='R5WG6'></ul><sub id='R5WG6'></sub></form><legend id='R5WG6'></legend><bdo id='R5WG6'><pre id='R5WG6'><center id='R5WG6'></center></pre></bdo></b><th id='R5WG6'></th></span></q></dt></tr></i><div id='R5WG6'><tfoot id='R5WG6'></tfoot><dl id='R5WG6'><fieldset id='R5WG6'></fieldset></dl></div>

      <small id='R5WG6'></small><noframes id='R5WG6'>

        • <bdo id='R5WG6'></bdo><ul id='R5WG6'></ul>

        目录的递归复制

        时间:2023-07-15

            <tbody id='d5qiO'></tbody>
            <i id='d5qiO'><tr id='d5qiO'><dt id='d5qiO'><q id='d5qiO'><span id='d5qiO'><b id='d5qiO'><form id='d5qiO'><ins id='d5qiO'></ins><ul id='d5qiO'></ul><sub id='d5qiO'></sub></form><legend id='d5qiO'></legend><bdo id='d5qiO'><pre id='d5qiO'><center id='d5qiO'></center></pre></bdo></b><th id='d5qiO'></th></span></q></dt></tr></i><div id='d5qiO'><tfoot id='d5qiO'></tfoot><dl id='d5qiO'><fieldset id='d5qiO'></fieldset></dl></div>
          • <legend id='d5qiO'><style id='d5qiO'><dir id='d5qiO'><q id='d5qiO'></q></dir></style></legend>

              • <tfoot id='d5qiO'></tfoot>

                <small id='d5qiO'></small><noframes id='d5qiO'>

                • <bdo id='d5qiO'></bdo><ul id='d5qiO'></ul>
                • 本文介绍了目录的递归复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我的旧 VPS 上,我使用以下代码将目录中的文件和目录复制到用户提交表单后创建的新目录中.

                  On my old VPS I was using the following code to copy the files and directories within a directory to a new directory that was created after the user submitted their form.

                  function copyr($source, $dest)
                  {
                     // Simple copy for a file
                     if (is_file($source)) {
                        return copy($source, $dest);
                     }
                  
                     // Make destination directory
                     if (!is_dir($dest)) {
                        mkdir($dest);
                        $company = ($_POST['company']);
                     }
                  
                     // Loop through the folder
                     $dir = dir($source);
                     while (false !== $entry = $dir->read()) {
                        // Skip pointers
                        if ($entry == '.' || $entry == '..') {
                           continue;
                        }
                  
                        // Deep copy directories
                        if ($dest !== "$source/$entry") {
                           copyr("$source/$entry", "$dest/$entry");
                        }
                     }
                  
                     // Clean up
                     $dir->close();
                     return true;
                  }
                  
                  copyr('Template/MemberPages', "Members/$company")
                  

                  但是现在在我的新 VPS 上,它只会创建主目录,而不会将任何文件复制到其中.我不明白这两个 VPS 之间会发生什么变化?

                  However now on my new VPS it will only create the main directory, but will not copy any of the files to it. I don't understand what could have changed between the 2 VPS's?

                  推荐答案

                  试试这个:

                  $source = "dir/dir/dir";
                  $dest= "dest/dir";
                  
                  mkdir($dest, 0755);
                  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());
                    }
                  }
                  

                  迭代器遍历所有文件夹和子文件夹,并将文件从 $source 复制到 $dest

                  Iterator iterate through all folders and subfolders and make copy of files from $source to $dest

                  这篇关于目录的递归复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 php 删除所有文件、文件夹及其子文件夹 下一篇:使用 PHP 删除空子文件夹

                  相关文章

                  <small id='8jHPS'></small><noframes id='8jHPS'>

                    <bdo id='8jHPS'></bdo><ul id='8jHPS'></ul>

                  <tfoot id='8jHPS'></tfoot>
                  1. <i id='8jHPS'><tr id='8jHPS'><dt id='8jHPS'><q id='8jHPS'><span id='8jHPS'><b id='8jHPS'><form id='8jHPS'><ins id='8jHPS'></ins><ul id='8jHPS'></ul><sub id='8jHPS'></sub></form><legend id='8jHPS'></legend><bdo id='8jHPS'><pre id='8jHPS'><center id='8jHPS'></center></pre></bdo></b><th id='8jHPS'></th></span></q></dt></tr></i><div id='8jHPS'><tfoot id='8jHPS'></tfoot><dl id='8jHPS'><fieldset id='8jHPS'></fieldset></dl></div>

                      <legend id='8jHPS'><style id='8jHPS'><dir id='8jHPS'><q id='8jHPS'></q></dir></style></legend>