当前位置:网站首页>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/'));
边栏推荐
- 软件开发模式之敏捷开发(scrum)
- 離線數倉和bi開發的實踐和思考
- Illustration of etcd access in kubernetes
- Proteus -- RS-232 dual computer communication
- JSP intelligent community property management system
- ERNIE1.0 与 ERNIE2.0 论文解读
- php中通过集合collect的方法来实现把某个值插入到数组中指定的位置
- SSM实验室设备管理
- oracle-外币记账时总账余额表gl_balance变化(上)
- Sqli-labs customs clearance (less2-less5)
猜你喜欢

叮咚,Redis OM对象映射框架来了

2021-07-05c /cad secondary development create arc (4)

The boss said: whoever wants to use double to define the amount of goods, just pack up and go

Oracle 11g uses ords+pljson to implement JSON_ Table effect

Proteus -- RS-232 dual computer communication

SSM second hand trading website

IDEA2020中测试PySpark的运行出错

CSRF攻击

MapReduce concepts and cases (Shang Silicon Valley Learning Notes)

Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
随机推荐
Sparksql data skew
ORACLE EBS 和 APEX 集成登录及原理分析
@Transational踩坑
Oracle EBS DataGuard setup
Use of interrupt()
MySQL has no collation factor of order by
SSM实验室设备管理
Network security -- intrusion detection of emergency response
Cognitive science popularization of middle-aged people
【BERT,GPT+KG调研】Pretrain model融合knowledge的论文集锦
@Transitional step pit
IDEA2020中测试PySpark的运行出错
The first quickapp demo
PM2 simple use and daemon
Oracle EBs and apex integrated login and principle analysis
Sqli labs customs clearance summary-page2
Yaml file of ingress controller 0.47.0
TCP attack
IDEA2020中PySpark的两表关联(字段名相同)
Feeling after reading "agile and tidy way: return to origin"