note 109053 added to function.copy
| From: | pavels dot osipovs at gmail dot com | Date: | Sat, 16 Jun 2012 14:41:01 +0000 |
| Subject: | note 109053 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188644@lists.php.net to get a copy of this message | ||
Function to copy non-empty folder with symlinks support. Based on function from cory at veck dot ca.
/**
* Copy folder with subfolders and files. Symlinks to folders and files are supported
* @param type $path
* @param type $dest
* @return type
*/
function _copy_folder( $path, $dest ) {
if ( is_dir( $path ) ) {
if ( is_link( $path ) ) {
// Copy symlink to directory
symlink( readlink( $path ), $dest );
return;
}
@mkdir( $dest );
$objects = scandir( $path );
if ( sizeof( $objects ) > 0 ) {
foreach ( $objects as $file ) {
if ( $file == "." || $file == ".." )
continue;
// go on
$what_to_copy = $path . '/' . $file;
$where_to_copy = $dest . '/' . $file;
if ( is_dir( $what_to_copy ) ) {
_copy_folder( $what_to_copy, $where_to_copy );
} else {
if ( is_link( $what_to_copy ) ) {
// Copy symlink to file
symlink( readlink( $what_to_copy ), $where_to_copy );
} else {
copy( $what_to_copy, $where_to_copy );
}
}
}
}
return true;
} elseif ( is_file( $path ) ) {
return copy( $path, $dest );
} else {
return false;
}
}
----
Server IP: 69.147.83.197
Probable Submitter: 84.245.212.71
----
Manual Page -- http://www.php.net/manual/en/function.copy.php
Edit -- https://master.php.net/note/edit/109053
Del: integrated -- https://master.php.net/note/delete/109053/integrated
Del: useless -- https://master.php.net/note/delete/109053/useless
Del: bad code -- https://master.php.net/note/delete/109053/bad+code
Del: spam -- https://master.php.net/note/delete/109053/spam
Del: non-english -- https://master.php.net/note/delete/109053/non-english
Del: in docs -- https://master.php.net/note/delete/109053/in+docs
Del: other reasons-- https://master.php.net/note/delete/109053
Reject -- https://master.php.net/note/reject/109053
Search -- https://master.php.net/manage/user-notes.php