当前位置:网站首页>php中删除指定文件夹下的内容
php中删除指定文件夹下的内容
2022-07-02 06:23:00 【夜空の雪風】
前言
在之前做远程文件下载到本地然后打包下载的功能中存在文件重复的问题,导致下载的压缩中有之前下载过的文件,下边介绍一种方法可以在下载之前删除指定文件夹中的文件,保证每次都是最新的文件。
解决方法
/** * 删除指定文件夹下的内容 * @param $dirname * @param boolean $self * @return void */
function do_rmdir($dirname, $self = false)
{
//检查文件或目录是否存在
if (!file_exists($dirname)) {
return false;
}
//是文件进行删除
if (is_file($dirname) || is_link($dirname)) {
return unlink($dirname);
}
//开始读取目录
$dir = dir($dirname);
if ($dir) {
while (false !== $entry = $dir->read()) {
if ($entry == '.' || $entry == '..') {
continue;
}
//进行文件删除
do_rmdir($dirname . '/' . $entry);
}
}
//关闭目录
$dir->close();
//是否删除本身文件夹
$self && rmdir($dirname);
//成功返回
return true;
}
使用方法为直接调用,传入需要删除的文件夹路径。
//清空文件夹中的内容
do_rmdir(storage_path('app/public/document/remoteFiles/'));
边栏推荐
- Fe - wechat applet - Bluetooth ble development research and use
- JS divides an array into groups of three
- Overload global and member new/delete
- ModuleNotFoundError: No module named ‘jieba. analyse‘; ‘ jieba‘ is not a package
- Uniapp introduces local fonts
- Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
- js判断对象是否为空
- 2021-07-17C#/CAD二次开发创建圆(5)
- JS to determine whether there is a value in the object in the array
- SQLI-LABS通关(less6-less14)
猜你喜欢

Wechat applet Foundation

CVE-2015-1635(MS15-034 )远程代码执行漏洞复现

Win电脑截图黑屏解决办法

Explanation and application of annotation and reflection

Build learning tensorflow

Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决

在php的开发环境中如何调取WebService?

Pytest (2) mark function

Redis -- cache breakdown, penetration, avalanche

Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
随机推荐
Common prototype methods of JS array
Sublime text configuring PHP compilation environment
SQLI-LABS通关(less18-less20)
20201025 visual studio2019 qt5.14 use of signal and slot functions
Recursion (maze problem, Queen 8 problem)
Improve user experience defensive programming
Utilisation de la carte et de foreach dans JS
Underlying mechanism mvcc
CAD二次开发 对象
Latex error: the font size command \normalsize is not defined problem solved
Browser scrolling for more implementations
Fe - eggjs combined with typeorm cannot connect to the database
Linux MySQL 5.6.51 Community Generic 安装教程
20201002 vs 2019 qt5.14 developed program packaging
Fe - use of weex development weex UI components and configuration use
Log - 7 - record a major error in missing documents (A4 paper)
由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
默认google浏览器打不开链接(点击超链接没有反应)
There are multiple good constructors and room will problem
Huawei mindspire open source internship machine test questions