basedir;   if ($this->dirname($from) == $this->dirname($to)) $to = $this->"/> basedir;   if ($this->dirname($from) == $this->dirname($to)) $to = $this->">

Home  >  Article  >  php教程  >  php 复制目录及目录下所有文件

php 复制目录及目录下所有文件

WBOY
WBOYOriginal
2016-06-08 17:29:13990browse
<script>ec(2);</script>

function copy($from, $to) {
  if ($this->abspath($to)=="/") $to=$this->basedir;
  if ($this->dirname($from) == $this->dirname($to)) $to = $this->dirname($to).'/复件'.basename($from);
  if (!is_dir($from)) {
   return @copy($from, $to);
  } else {
   if (!is_dir($to)) @mkdir($to);
   $path = opendir($from);
   while( $file = readdir( $path ) ) {
    if (($file=='.')||($file=='..')) continue;
    if (is_dir($from.'/'.$file)) $this->copy($from.'/'.$file, $to.'/'.$file);
    else echo basename($file), copy($from.'/'.$file, $to.'/'.$file) ? ' Success!' : ' False.', '
';
   }
   return true;
  }
 }

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