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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错