[英]Codeigniter : Delete directory after deleting all files
I want to delete a folder after deleting all the files inside it, in my codeigniter project. 我想在删除文件夹中的所有文件后,在我的codeigniter项目中删除该文件夹。 Lets say my folder name is upload
, which is located near the application folder in my ci
project. 可以说我的文件夹名称是upload
,它位于ci
项目中的application文件夹附近。
The upload
folder contains Peniyal
as a sub-folder and it contains 4 images inside it. upload
文件夹包含Peniyal
作为子文件夹,并且其中包含4张图像。 I need that 4 images to be deleted, next the sub-folder has to be deleted. 我需要删除4张图片,然后必须删除该子文件夹。 upload
folder should not be deleted. upload
文件夹不应删除。 I am hanging my mind to do it. 我很想这样做。 So far I have tried the following:- 到目前为止,我已经尝试了以下方法:
$files = glob('./upload/Peniyal');//to get all file names
//am not sure whether the path is correctly given..
foreach($files as $file){ // iterate files one by one
if(is_file($file))
unlink($file); // delete file
}
$path = './upload/Peniyal';
rmdir($path);
Any help will be appreciated. 任何帮助将不胜感激。 Thx! 谢谢!
The glob()
function matches a pattern, but you are not providing one. glob()
函数匹配一种模式,但是您没有提供一种。 So if you use the pattern *.*
the glob
will find all files in that folder. 因此,如果您使用模式*.*
则glob
将在该文件夹中找到所有文件。
// match any file
$files = glob('./upload/Peniyal/*.*');
foreach($files as $file){
if(is_file($file))
unlink($file);
}
$path = './upload/Peniyal';
rmdir($path);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.