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;
        }
    }

原文地址:https://www.cnblogs.com/wanghaodong/p/9482647.html