Home > Backend Development > PHP Tutorial > php删除文件夹下的所有文件

php删除文件夹下的所有文件

WBOY
Release: 2016-06-20 12:34:42
Original
1004 people have browsed it

直接上代码

   public function delpath($path){       if($handle=opendir($path)){                 while(false!==($file=readdir($handle))){                     if ($file != "." && $file != "..") {                         @unlink($path."".$file);                     }                 }             }           }
Copy after login

其实主要的思路就是,首先获取文件夹下的所有文件,并将其遍历出来,当然我这个是在项目中已经提前知道我这个是文件,不是文件夹。在遍历的同时再进行一一删除。

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template