Copy files and folder recursive


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

Copy all files and directories from src to dest.


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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.