Home > php教程 > php手册 > 休息时间,分享一个清空目录下所有文件的代码

休息时间,分享一个清空目录下所有文件的代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 11:45:09
Original
1175 people have browsed it

只需要一个路径,和一个可选的参数,就可以删除该路径下所有文件(可选删除目录本身)
/**<br>  * 清空目录<br>  * @param string $path 目录路径  <br>  * @param bool $rmdir 若为真,则删除目录本身<br>  * @return bool<br>  * @author  吾爱<br>  */<br> function qkdir($path,$rmdir=false){<br>     if(!is_dir($path)){<br>         return false;<br>     }<br>     if($handle=opendir($path)){<br>         while(false!==($item=readdir($handle))){<br>             if($item=="." || $item==".."){<br>                 continue;<br>             }<br>             $item=rtrim($path,"/")."/".$item;<br>             if(is_dir($item)){<br>                 qkdir($item);<br>                 @rmdir($item);<br>                 continue;<br>             }<br>             @unlink($item);<br>         }<br>         closedir($handle);//关闭句柄<br>     }<br>     if($rmdir){<br>         @rmdir($path);<br>     }<br>     return TRUE;<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

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