function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst, 0777);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
$this->recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
Example : How to use above Function
$src='www/abc'; // copy all the files and folder within abc directory
$dst = 'www/newdir' //
recurse_copy($src,$dst);
above function first create the destination directory and than copy all the source directory content.
Tips: to create directory and set its permission using following code in php
mkdir($path, 0777, true)
$dir = opendir($src);
@mkdir($dst, 0777);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
$this->recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
Example : How to use above Function
$src='www/abc'; // copy all the files and folder within abc directory
$dst = 'www/newdir' //
recurse_copy($src,$dst);
above function first create the destination directory and than copy all the source directory content.
Tips: to create directory and set its permission using following code in php
mkdir($path, 0777, true)
No comments:
Post a Comment