I searched all morning for this.
Is there a simple PHP function that will duplicate a folder on my server, temporarily changing permissions on the path, if necessary? Basically an alternative to PHP for me using FTP to copy the entire folder down and then back it up?
I tried the function below, which I found on the Internet, but it does nothing, I think, probably due to permissions. I tried it with error_reporting(E_ALL); , and also checked the return value of each copy() , they all returned false.
copy_directory('/directory1','/directory2') function copy_directory($src,$dst) { $dir = opendir($src); @mkdir($dst); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { if ( is_dir($src . '/' . $file) ) { copy_directory($src . '/' . $file,$dst . '/' . $file); } else { copy($src . '/' . $file,$dst . '/' . $file); } } } closedir($dir); }
source share