Thinkphp5.1+ 删除所有runtime记录

浏览:1588 发布日期:2019/04/26 分类:技术分享 关键字: thinkphp runtime
<?php

    public function delRuntime() {
        $path = env('RUNTIME_PATH');
        //如果是目录则继续
        if (!is_dir($path)) {
            echo 'runtime目录不存在';
            exit;
        }
        //扫描一个文件夹内的所有文件夹和文件并返回数组
        $p = scandir($path);
        $arr = ['cache', 'log', 'temp'];
        foreach ($p as $val) {
            if (!in_array($val, $arr)) {
                continue;
            }
            if (!is_dir($path . $val)) {
                continue;
            }
            $dir = $path . $val . '/';
            //先删除目录下的文件:
            $dh = opendir($dir);
            while ($file = readdir($dh)) {
                if ($file != "." && $file != "..") {
                    $fullpath = $dir . "/" . $file;
                    if (!is_dir($fullpath)) {
                        @unlink($fullpath);
                    } else {
                        deldir($fullpath);
                    }
                }
            }
            closedir($dh);
            @rmdir($path . $val . '/');
        }
        echo '删除runtime成功';
        exit;
    }
相关代码关注:https://code.wangjianbo.cn/info/133/
最佳答案
评论( 相关
后面还有条评论,点击查看>>