笔记 · · 594 阅读

删除文件夹下所有文件

PHP demo
    //删除文件夹下所有文件
    public function delFiles($dir = './Public/Cache/')
    {
        $dh = opendir($dir);
        while ($file = readdir($dh)) {
            if ($file != "." && $file != "..") {
                $fullpath = $dir . "/" . $file;
                if (!is_dir($fullpath)) {
                    unlink($fullpath);
                } else {
                    delFiles($fullpath);
                }
            }
        }
        closedir($dh);
    }
    //调用
    public function del()
    {
        $this->delFiles('./111111/');
    }