PHP fopen 403(FPDF)

时间:2018-12-11 21:16:55

标签: php curl fopen fpdf

我使用库FPDF生成文件,并且使用fopen方法遇到问题,我通过URL加载图像,生成qrcodes图像等... fopen在新的服务器中不起作用,但在phpinfo中,allow_url_fopen是:On

我尝试使用cURL重建方法,但这并不容易

protected function _parsepng($file) {
    // Extract info from a PNG file
    $fopen = false;
    if ($fopen){
        $f = fopen($file, 'rb');
        if (!$f)
            $this->Error('Can\'t open image file: ' . $file);
        $info = $this->_parsepngstream($f, $file);
        fclose($f);
        return $info;
    } else {
        $f = fopen('php://temp', 'w+');
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $file);
        curl_setopt($ch, CURLOPT_FILE, $f);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        //curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //curl_setopt($ch, CURLOPT_POSTFIELDS,[]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_exec($ch);
        if (!$f)
            $this->Error('Can\'t open image file: ' . $file);
        $info = $this->_parsepngstream($f, $file);
        curl_close($ch);
        return $info;
    }
}

有人可以解决吗?

0 个答案:

没有答案