当前位置:网站首页>Delete the contents under the specified folder in PHP
Delete the contents under the specified folder in PHP
2022-07-02 07:20:00 【Snow wind in the night sky】
Preface
There was a problem of duplicate files in the previous function of downloading remote files locally and then packaging them , As a result, there are previously downloaded files in the downloaded compression , The following is a method to delete the files in the specified folder before downloading , Ensure the latest documents every time .
resolvent
/** * Delete the contents under the specified folder * @param $dirname * @param boolean $self * @return void */
function do_rmdir($dirname, $self = false)
{
// Check if the file or directory exists
if (!file_exists($dirname)) {
return false;
}
// Is a file to delete
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
// Start reading directory
$dir = dir($dirname);
if ($dir) {
while (false !== $entry = $dir->read()) {
if ($entry == '.' || $entry == '..') {
continue;
}
// Delete the file
do_rmdir($dirname . '/' . $entry);
}
}
// Close directory
$dir->close();
// Whether to delete its own folder
$self && rmdir($dirname);
// Successfully returns
return true;
}
The use method is to call directly , Pass in the folder path that needs to be deleted .
// Empty the contents of the folder
do_rmdir(storage_path('app/public/document/remoteFiles/'));
边栏推荐
- Oracle rman半自动恢复脚本-restore阶段
- ORACLE EBS 和 APEX 集成登录及原理分析
- php中时间戳转换为毫秒以及格式化时间
- Oracle RMAN semi automatic recovery script restore phase
- 实现接口 Interface Iterable<T>
- ssm超市订单管理系统
- 【信息检索导论】第三章 容错式检索
- Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
- 华为机试题-20190417
- MySQL中的正则表达式
猜你喜欢

MapReduce concepts and cases (Shang Silicon Valley Learning Notes)

Sparksql data skew

Take you to master the formatter of visual studio code

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

腾讯机试题

Basic knowledge of software testing

Oracle EBS ADI development steps

ssm垃圾分类管理系统

外币记账及重估总账余额表变化(下)

How to efficiently develop a wechat applet
随机推荐
離線數倉和bi開發的實踐和思考
Yaml file of ingress controller 0.47.0
sparksql数据倾斜那些事儿
MySQL has no collation factor of order by
php中树形结构转数组(拉平树结构,保留上下级排序)
2021-07-05c /cad secondary development create arc (4)
Network security -- intrusion detection of emergency response
allennlp 中的TypeError: Object of type Tensor is not JSON serializable错误
【信息检索导论】第一章 布尔检索
ORACLE APEX 21.2安装及一键部署
User login function: simple but difficult
Oracle apex 21.2 installation and one click deployment
Oracle rman自动恢复脚本(生产数据向测试迁移)
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization
PM2 simple use and daemon
oracle-外币记账时总账余额表gl_balance变化(上)
pySpark构建临时表报错
php中计算树状结构数据中的合计
【Torch】解决tensor参数有梯度,weight不更新的若干思路
Ingress Controller 0.47.0的Yaml文件