php文件操作
文件夹及其子文件复制:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public function aa($path,$path1){  if(is_file($path1)){    return  "指定路径不可用"; }  if(!file_exists($path1)){    mkdir($path1); }  if(is_dir($path1)){    $handle=opendir($path);    while ($file=readdir($handle)){      if ($file!="."&&$file!=".."){        $p=$path."/".$file;        $p1=$path1."/".$file;        if(file_exists($p1)){          $arr=explode(".",$file);          $first=array_shift($arr);          $last=array_pop($arr);          $file=$first."(1).".$last;       }        $p1=$path1."/".$file;        if (is_dir($p)){          aa($p,$p1);       }       if(is_file($p)){          copy($p,$p1);       }     }   }    closedir($handle); } } | 
删除文件:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | function deldir($path) {  if (file_exists($path)) {    $dir_handle = opendir($path);    while ($file = @readdir($dir_handle)) {      if ($file != "." && $file != "..") {        $p = $path . "/" . $file;        if (is_dir($p)) {          deldir($p);       }        if (is_file($p)) {          unlink($p);       }     }   }    rmdir($path);    closedir($dir_handle); } } |