Posted By

fedek6 on 04/22/14


Tagged

recursive copy cp


Versions (?)

Copy files and folder recursive


 / Published in: PHP
 

Copy all files and directories from src to dest.

  1. // copy recursive
  2. function cpy($source, $dest){
  3. if(is_dir($source)) {
  4. $dir_handle=opendir($source);
  5. while($file=readdir($dir_handle)){
  6. if($file!="." && $file!=".."){
  7. if(is_dir($source."/".$file)){
  8. if(!is_dir($dest."/".$file)){
  9. mkdir($dest."/".$file);
  10. }
  11. cpy($source."/".$file, $dest."/".$file);
  12. } else {
  13. copy($source."/".$file, $dest."/".$file);
  14. }
  15. }
  16. }
  17. closedir($dir_handle);
  18. } else {
  19. copy($source, $dest);
  20. }
  21. }

Report this snippet  

You need to login to post a comment.