当前位置:网站首页>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/'));
边栏推荐
- php中删除指定文件夹下的内容
- Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
- ORACLE 11G SYSAUX表空间满处理及move和shrink区别
- 使用Matlab实现:弦截法、二分法、CG法,求零点、解方程
- ORACLE 11G利用 ORDS+pljson来实现json_table 效果
- Oracle apex Ajax process + dy verification
- 搭建frp进行内网穿透
- php中的二维数组去重
- Take you to master the formatter of visual studio code
- 使用 Compose 实现可见 ScrollBar
猜你喜欢
随机推荐
Sqli-labs customs clearance (less1)
CSRF attack
ORACLE APEX 21.2安裝及一鍵部署
MySQL has no collation factor of order by
软件开发模式之敏捷开发(scrum)
php中的数字金额转换大写数字
離線數倉和bi開發的實踐和思考
TCP攻击
Oracle RMAN semi automatic recovery script restore phase
MapReduce与YARN原理解析
TCP attack
php中树形结构转数组(拉平树结构,保留上下级排序)
中年人的认知科普
Agile development of software development pattern (scrum)
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Feeling after reading "agile and tidy way: return to origin"
Illustration of etcd access in kubernetes
Data warehouse model fact table model design
ORACLE EBS接口开发-json格式数据快捷生成
CAD secondary development object









