Folder copy (both win&linux)

WBOY
Release: 2016-07-25 09:06:48
Original
976 people have browsed it
复制文件夹到另一个地方。
/**
  1. /**
  2. * Copy the folder
  3. eg: copy D:/wwwroot/wordpress to
  4. D:/wwwroot/www/explorer/0000/del/1/
  5. No need to add a slash at the end , if you copy to the address without adding the source folder name,
  6. the files under wordpress will be copied to D:/wwwroot/www/explorer/0000/del/1/
  7. * $from = 'D:/wwwroot/wordpress' ;
  8. * $to = 'D:/wwwroot/www/explorer/0000/del/1/wordpress';
  9. */
  10. function copy_dir($source, $dest){
  11. $result = false;
  12. if (is_file($source)) {
  13. if ($dest[strlen($dest)-1] == '/') {
  14. $__dest = $dest . "/" . basename($source);
  15. } else {
  16. $__dest = $dest;
  17. }
  18. $result = @copy($source, $__dest);
  19. //echo iconv( $config['app_charset'],$config['system_charset'], $source);
  20. @chmod($__dest, 0755);
  21. }elseif (is_dir($source)) {
  22. if ($dest[strlen($dest)-1] == '/') {
  23. $dest = $dest . basename($source);
  24. @mkdir($dest);
  25. @chmod($dest, 0755);
  26. } else {
  27. @mkdir($dest, 0755);
  28. @chmod($dest, 0755);
  29. }
  30. $dirHandle = opendir($source);
  31. while ($file = readdir($dirHandle)) {
  32. if ($file != "." && $file != "..") {
  33. if (!is_dir($source . "/" . $file)) {
  34. $__dest = $dest . "/" . $file;
  35. } else {
  36. $__dest = $dest . "/" . $file;
  37. }
  38. $result = copy_dir($source . "/" . $file, $__dest);
  39. }
  40. }
  41. closedir($dirHandle);
  42. } else {
  43. $result = false;
  44. }
  45. return $result;
  46. }
复制代码


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!