Home  >  Article  >  Backend Development  >  PHP realizes the copy function of the entire directory

PHP realizes the copy function of the entire directory

WBOY
WBOYOriginal
2016-07-25 08:45:311054browse
  1. function copy_dir($src,$dst) {
  2. $dir = opendir($src);
  3. @mkdir($dst);
  4. while(false !== ( $file = readdir($dir)) ) {
  5. if (( $file != '.' ) && ( $file != '..' )) {
  6. if ( is_dir($src . '/' . $file) ) {
  7. copy_dir($src . '/' . $file,$dst . '/' . $file);
  8. continue;
  9. }
  10. else {
  11. copy($src . '/' . $file,$dst . '/' . $file);
  12. }
  13. }
  14. }
  15. closedir($dir);
  16. }
  17. copy_dir('目录1','目录2');
复制代码

PHP


Statement:
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