Posted By

dmautz1 on 10/15/09


Tagged

php folder copy


Versions (?)

PHP Copy Source Folder to Destination


 / Published in: PHP
 

Easily copy a folder to a new destination.

  1. <?
  2. function copy_directory( $source, $destination ) {
  3. if ( is_dir( $source ) ) {
  4. @mkdir( $destination );
  5. $directory = dir( $source );
  6. while ( FALSE !== ( $readdirectory = $directory->read() ) ) {
  7. if ( $readdirectory == '.' || $readdirectory == '..' ) {
  8. continue;
  9. }
  10. $PathDir = $source . '/' . $readdirectory;
  11. if ( is_dir( $PathDir ) ) {
  12. copy_directory( $PathDir, $destination . '/' . $readdirectory );
  13. continue;
  14. }
  15. copy( $PathDir, $destination . '/' . $readdirectory );
  16. }
  17.  
  18. $directory->close();
  19. }else {
  20. copy( $source, $destination );
  21. }
  22. }
  23. ?>

Report this snippet  

You need to login to post a comment.