Heim  >  Artikel  >  Backend-Entwicklung  >  PHP实现整个目录的拷贝功能

PHP实现整个目录的拷贝功能

WBOY
WBOYOriginal
2016-07-25 08:45:311054Durchsuche
  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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn