PHP Copy Source Folder to Destination


/ Published in: PHP
Save to your folder(s)

Easily copy a folder to a new destination.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.