Title: (Pull Request) Error while copying a dir while cloning
Last modified: August 22, 2016

---

# (Pull Request) Error while copying a dir while cloning

 *  Resolved [ricardozanini](https://wordpress.org/support/users/ricardozanini/)
 * (@ricardozanini)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/pull-request-error-while-copying-a-dir-while-cloning/)
 * Hello guys!
 * I was creating some subsites using your plugin and while copying from a site 
   with multiples posts, files and pages everything went fine.
 * Therefore when copying from a template site only with a few configuration, appearance
   and plugin options occurs a error trying to copy dirs and files that don’t exist.
 * The full log:
 *     ```
       [Wed Sep 17 10:35:49 2014] [error] [client 10.10.2.27] PHP Warning:  copy(/var/www/html/wordpress/wp-content/uploads/sites/13/) [<a href='function.copy'>function.copy</a>]: failed to open stream: No such file or directory in /var/www/html/wordpress/wp-content/plugins/multisite-cloner/multisite-cloner.php on line 423, referer: http://mycompany.com/wp-admin/network/site-new.php
       [Wed Sep 17 10:35:49 2014] [error] [client 10.10.2.27] PHP Warning:  readdir() expects parameter 1 to be resource, boolean given in /var/www/html/wordpress/wp-content/plugins/multisite-cloner/multisite-cloner.php on line 417, referer: http://mycompany.com/wp-admin/network/site-new.php
       [Wed Sep 17 10:35:49 2014] [error] [client 10.10.2.27] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /var/www/html/wordpress/wp-content/plugins/multisite-cloner/multisite-cloner.php on line 423, referer: http://mycompany.com/wp-admin/network/site-new.php
       ```
   
 * The problem was at the line 423 on a function called cloner_recurse_copy. The
   function tries to open a dir and then some recursive copy should be made. The
   problem is: there isn´t a validation code after tried to open the source dir.
   After a simple guard code everything worked like a charm. It is possible to add
   this little correction on a new plugin version?
 *     ```
       function cloner_recurse_copy($src, $dst) {
           $dir = opendir($src); 
   
           // maybe I am not a dir after all.
           if(!$dir || !is_dir($dir)) {
               return;
           }
   
           if (!file_exists($dst)) {
               mkdir($dst);
           }
   
           while(false !== ( $file = readdir($dir)) ) {
               if (( $file != '.' ) && ( $file != '..' )) {
                   if ( is_dir($src . '/' . $file) ) {
                       cloner_recurse_copy($src . '/' . $file,$dst . '/' . $file);
                   }
                   else {
                       copy($src . '/' . $file,$dst . '/' . $file);
                   }
               }
           } 
   
           closedir($dir);
       }
       ```
   
 * Thanks!!
 * [https://wordpress.org/plugins/multisite-cloner/](https://wordpress.org/plugins/multisite-cloner/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Patricio T](https://wordpress.org/support/users/pmtarantino/)
 * (@pmtarantino)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/pull-request-error-while-copying-a-dir-while-cloning/#post-5304270)
 * Done. We edit the function and now it should work fine.
 *  Thread Starter [ricardozanini](https://wordpress.org/support/users/ricardozanini/)
 * (@ricardozanini)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/pull-request-error-while-copying-a-dir-while-cloning/#post-5304271)
 * Thanks! Looking forward the new version.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘(Pull Request) Error while copying a dir while cloning’ is closed to 
new replies.

 * ![](https://ps.w.org/multisite-cloner/assets/icon-256x256.png?rev=1067125)
 * [Multisite Cloner](https://wordpress.org/plugins/multisite-cloner/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multisite-cloner/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multisite-cloner/)
 * [Active Topics](https://wordpress.org/support/plugin/multisite-cloner/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multisite-cloner/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multisite-cloner/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [ricardozanini](https://wordpress.org/support/users/ricardozanini/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/pull-request-error-while-copying-a-dir-while-cloning/#post-5304271)
 * Status: resolved