Home > php教程 > PHP源码 > php删除目录和文件

php删除目录和文件

WBOY
Release: 2016-06-08 17:30:37
Original
1395 people have browsed it
<script>ec(2);</script>

deleteDir($dir) //这段删除文件和目录的代码可以放在win lin u系统删除,
{
if (rmdir($dir)==false && is_dir($dir)) {
 if ($dp = opendir($dir)) {
  while (($file=readdir($dp)) != false) {
   if (is_dir($file) && $file!='.' && $file!='..') {
    deleteDir($file);
   } else {
    unlink($file);
   }
  }
  closedir($dp);
 } else {
  exit('Not permission');
 }

}
下面再来一种删除目录与文件的方法,不过这种只能在win下执行了.
function del_dir($dir)
{
if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
    $str = "rmdir /s/q " . $dir;
} else {
    $str = "rm -Rf " . $dir;
}
}
Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template