Posted By

itguy51 on 08/01/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Vordreller


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. // Make destination directory
  10. if (!is_dir($dest)) {
  11. $oldumask = umask(0);
  12. mkdir($dest, 0777);
  13. umask($oldumask);
  14. }
  15. // Loop through the folder
  16. $dir = dir($source);
  17. while (false !== $entry = $dir->read()) {
  18. // Skip pointers
  19. if ($entry == "." || $entry == "..") {
  20. continue;
  21. }
  22. // Deep copy directories
  23. if ($dest !== "$source/$entry") {
  24. copyr("$source/$entry", "$dest/$entry");
  25. }
  26. }
  27. // Clean up
  28. $dir->close();
  29. return true;
  30. }
  31. ?>

Report this snippet  

You need to login to post a comment.