duanhui4160 2017-05-29 11:48
浏览 26
已采纳

Codeigniter:删除所有文件后删除目录

I want to delete a folder after deleting all the files inside it, in my codeigniter project. Lets say my folder name is upload, which is located near the application folder in my ci project.

The upload folder contains Peniyal as a sub-folder and it contains 4 images inside it. I need that 4 images to be deleted, next the sub-folder has to be deleted.upload folder should not be deleted. 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);

Folder Structure

Any help will be appreciated. Thx!

  • 写回答

1条回答 默认 最新

  • dongxing1412 2017-05-29 12:06
    关注

    The glob() function matches a pattern, but you are not providing one. So if you use the pattern *.* the glob will find all files in that folder.

    // match any file
    $files = glob('./upload/Peniyal/*.*');
    
    foreach($files as $file){
        if(is_file($file))
            unlink($file);
    }
    $path   = './upload/Peniyal'; 
    rmdir($path);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?