PHP删除临时文件

/**
    * 下载后直接删除临时文件
    */  
    public function deldir($dir) {
        $dh=opendir($dir);
        while ($file=readdir($dh)) {
        if($file!="." && $file!="..") {
                $fullpath=$dir."/".$file;
                if(!is_dir($fullpath)) {
                    //$path = iconv('utf-8','gbk',$fullpath);
                    unlink($fullpath);
                } else {
                    $this->deldir($fullpath);
                }
            }
        }
        closedir($dh);
        if(rmdir($dir)) {
            return true;
        } else {
            return false;
        }
    }

posted @ 2018-08-15 17:14  王浩栋  阅读(867)  评论(0编辑  收藏  举报