当前位置:网站首页>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/'));
边栏推荐
- Ding Dong, here comes the redis om object mapping framework
- ORACLE APEX 21.2安装及一键部署
- Three principles of architecture design
- MySQL无order by的排序规则因素
- 【信息检索导论】第七章搜索系统中的评分计算
- MySQL has no collation factor of order by
- 使用Matlab实现:幂法、反幂法(原点位移)
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- Cognitive science popularization of middle-aged people
- SSM二手交易网站
猜你喜欢
Take you to master the formatter of visual studio code
Principle analysis of spark
Spark SQL task performance optimization (basic)
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
spark sql任务性能优化(基础)
MySQL无order by的排序规则因素
【信息检索导论】第七章搜索系统中的评分计算
How to call WebService in PHP development environment?
【模型蒸馏】TinyBERT: Distilling BERT for Natural Language Understanding
Yolov5 practice: teach object detection by hand
随机推荐
Oracle EBS interface development - quick generation of JSON format data
Principle analysis of spark
Oracle RMAN semi automatic recovery script restore phase
Spark SQL task performance optimization (basic)
Oracle 11g uses ords+pljson to implement JSON_ Table effect
Yolov5 practice: teach object detection by hand
Oracle段顾问、怎么处理行链接行迁移、降低高水位
php中获取汉字拼音大写首字母
第一个快应用(quickapp)demo
Laravel8中的find_in_set、upsert的使用方法
How to call WebService in PHP development environment?
Oracle EBS数据库监控-Zabbix+zabbix-agent2+orabbix
php中在二维数组中根据值返回对应的键值
类加载器及双亲委派机制
Explanation of suffix of Oracle EBS standard table
Basic knowledge of software testing
腾讯机试题
使用 Compose 实现可见 ScrollBar
Alpha Beta Pruning in Adversarial Search
ORACLE 11G利用 ORDS+pljson来实现json_table 效果