当前位置:网站首页>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;
}
批注:
用于个人总结,菜鸟一枚大佬轻喷,如有问题欢迎指证,如果对大家有帮助那再好不过;
边栏推荐
- apache atlas断点查看
- TLBB series of Tianlong Babu - online single use database modified to other sects
- In order to prevent being rectified after 00, a company requires employees not to sue the company
- After 3 years of testing experience, do you know the state transition method for use case design?
- BOE: with the arrival of the peak season in the second half of the year, the promotion and the release of new products, the demand is expected to improve
- MySQL error: expression 1 of order by claim is not in group by claim and contains nonaggregated column
- Which version of JVM is the fastest?
- Profil de risque de monnaie stable: l'usdt et l'USDC sont - ils sûrs?
- MATLAB给数据加噪声/扰动
- curl: (56) Recv failure: Connection reset by peer
猜你喜欢

Huaxia Fund: sharing of digital transformation practice achievements in the fund industry

隐私计算助力数据的安全流通与共享

After reading the complete code

To solve the stubborn problem of Lake + warehouse hybrid architecture, Star Ring Technology launched an independent controllable cloud native Lake warehouse integrated platform

Why does selenium become the first choice for web automated testing? (source code attached)

After 3 years of testing experience, do you know the state transition method for use case design?

把这份关于软件测试一系列笔记研究完,进大厂是个“加分项”...

毕业生迷茫,中年人焦虑,职场路怎么越走越宽?

C# Winfrom Chart图表控件 柱状图、折线图

MySQL foundation - multi table query
随机推荐
「BUAA OO Unit 4 HW16」第四单元总结与课程回顾
The rooster Electronic Society graphical programming real questions and answers analysis of the scratch grade test level 1 June 2022
【OpenGL】杂谈一、通过鼠标拖拽实现相机绕空间中的某点进行球面旋转查看
Time format GTM to Beijing time
京东方:随着下半年旺季到来、促销拉动、新产品发布等影响,需求有望出现好转
Locust performance pressure test tool
Telnet+ftp to control and upgrade the equipment
Key sprite fighting monsters - window binding skill
Real test = "half product + Half development"?
分片信息调哪个参数呢?用的是MySQLsource stream api,不是table api
C语言——printf打印进制前缀
【Proteus仿真】数码管递加/递减带闪烁消隐显示
新股民如何网上开户?究竟网上开户是否安全么?
DAP大屏主题开发说明
Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
指南针开户炒股是否安全?个人怎样开户炒股
加速智能驾驶项目落地?你还缺一套真值测评系统
telnet+ftp 对设备进行 操控 和 升级
【Proteus仿真】8位数码管动态扫描显示变化数据
What memory consuming data is stored in MySQL CDC jobmanager?