note 109053 deleted from function.copy by danbrown

From: Date: Sun, 17 Jun 2012 14:33:07 +0000
Subject: note 109053 deleted from function.copy by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188655@lists.php.net to get a copy of this message
Note Submitter: pavels dot osipovs at gmail dot com ---- 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; } }

« previous php.notes (#188655) next »