0 0 votes
Article Rating
Bulk Copy Directory Recursively to new folder:
This function is used to copy a folder and all its contents and sub folders, its params are as follows:
1) The source folder path
2) The destination path (should not exist)
function custom_copy($src, $dst) {
// open the source directory
$dir = opendir($src);
// Make the destination directory if not exist
@mkdir($dst);
// Loop through the files in source directory
while( $file = readdir($dir) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) )
{
// Recursively calling custom copy function
// for sub directory
custom_copy($src . '/' . $file, $dst . '/' . $file);
}
else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
$src = __DIR__.'/folder-2';
$dst = __DIR__.'/folder-3';
custom_copy($src, $dst);
Special Notes:
For PHP >= 5.3.0 try
PHP magic constants.
__DIR__
And make your path relative.
For PHP < 5.3.0 try
dirname(__FILE__)
0 0 votes
Article Rating