Posted By

itguy51 on 08/01/10


Tagged


Versions (?)

dir_copy


 / Published in: PHP
 

  1. <?php
  2. function copyr($source, $dest){
  3. // Simple copy for a file
  4. if (is_file($source)) {
  5. $c = copy($source, $dest);
  6. chmod($dest, 0777);
  7. return $c;
  8. }
  9.  
  10. // Make destination directory
  11. if (!is_dir($dest)) {
  12. $oldumask = umask(0);
  13. mkdir($dest, 0777);
  14. umask($oldumask);
  15. }
  16.  
  17. // Loop through the folder
  18. $dir = dir($source);
  19. while (false !== $entry = $dir->read()) {
  20. // Skip pointers
  21. if ($entry == "." || $entry == "..") {
  22. continue;
  23. }
  24.  
  25. // Deep copy directories
  26. if ($dest !== "$source/$entry") {
  27. copyr("$source/$entry", "$dest/$entry");
  28. }
  29. }
  30.  
  31. // Clean up
  32. $dir->close();
  33. return true;
  34. }
  35. ?>

Report this snippet  

You need to login to post a comment.