当前位置:网站首页>PHP删除目录
PHP删除目录
2022-06-29 16:21:00 【若得一匹】
项目场景:PHP删除指定目录
public function deldir($dir) {
//先删除目录下的文件:
if(is_dir($dir)){
$dh = opendir($dir);
while ($file = readdir($dh)) {
if($file != "." && $file!="..") {
$fullpath = $dir."/".$file;
if(!is_dir($fullpath)) {
//判断文件创建时间 超出时间则删除
$file_size=filemtime($fullpath);
if($file_size<(time()-3600*24)){
@unlink($fullpath);
}
} else {
$this->deldir($fullpath);
}
}
}
closedir($dh);
//删除当前文件夹:
if(@rmdir($dir)) {
return true;
} else {
return false;
}
}
}
//获取目录大小 该方法上面没用到只是留个笔记
function dirsize($dir)
{
@$dh = opendir($dir);
$size = 0;
while ($file = @readdir($dh)) {
if ($file != "." and $file != "..") {
$path = $dir . "/" . $file;
if (is_dir($path)) {
$size += $this->dirsize($path);
} elseif (is_file($path)) {
$size += filesize($path);
}
}
}
@closedir($dh);
return $size;
}
批注:
用于个人总结,菜鸟一枚大佬轻喷,如有问题欢迎指证,如果对大家有帮助那再好不过;
边栏推荐
- SSL free certificate application, how about the actual effect of free SSL certificate?
- telnet+ftp 对设备进行 操控 和 升级
- Privacy computing helps secure data circulation and sharing
- Accelerate the implementation of intelligent driving projects? You still lack a truth evaluation system
- Review of mathematical knowledge: curve integral of type I
- UWB精准定位方案,厘米级高精度技术应用,智能配对感应技术
- curl: (56) Recv failure: Connection reset by peer
- Which parameter is the partition information adjusted? The MySQL source stream API is used, not the table API
- 能够1年涨薪2次的软件测试工程师,他到底强在哪里?
- A tour of gRPC:02 - 从proto生成代码
猜你喜欢

能够1年涨薪2次的软件测试工程师,他到底强在哪里?

Metadata management Apache Atlas Compilation integration deployment and testing

破解湖+仓混合架构顽疾,星环科技推出自主可控云原生湖仓一体平台

或许再过两年,ASML将可以自由给中国供应EUV光刻机

Accelerate the implementation of intelligent driving projects? You still lack a truth evaluation system

美国芯片再遭重击,Intel或将被台积电击败而沦落至全球第三

图文带你彻底弄懂MySQL事务原子性之UndoLog

Selenium 凭什么成为 Web 自动化测试的首选?(内附源码)

MATLAB给数据加噪声/扰动

curl: (56) Recv failure: Connection reset by peer
随机推荐
After eight years of testing and opening experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers
It's also a test. Why do others get an annual salary of 30w+?
全面剖析Seata 分布式事务 AT 与XA
leetcode:139. Word splitting [DFS + memory]
DTCC2022 中国数据库技术大会最新议程出炉
「科普大佬说」AI与创造力
MySQL cdc jobmanager 中存了哪些比较耗内存的数据呢?
Cortical traceability analysis of ERP
把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...
How to configure logback? 30 minutes for you to thoroughly learn the code to stay up late and knock
2022年有哪些适合穷人的理财产品?
MySQL error: expression 1 of order by claim is not in group by claim and contains nonaggregated column
UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
Technology sharing | broadcast function design in integrated dispatching
apache atlas断点查看
Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
Accelerate the implementation of intelligent driving projects? You still lack a truth evaluation system
高级性能测试工程师面试必问十大问题
telnet+ftp 对设备进行 操控 和 升级
如何配置 logback?30分钟让你彻底学会代码熬夜敲