FPDF issue while generating pdf with images due to PHP 'allow_url_fopen' setting

只愿长相守 提交于 2019-12-12 17:22:51

问题


I am facing a problem with FPDF while generating the PDF file with images as explained here. Finally I found the reason for this issue but I am not sure how to fix that one, can anybody suggest some good solution to handle that issue.

This problem is due to the allow_url_fopen setting of my server, if I enable that setting then the FPDF library is generating the PDF file with images also without any errors.

I am using this FPDF library for one of my client sites, he(client) disabled the 'allow_url_fopen' setting for security reasons and he is not intersted to enable that setting. how can I solve this issue with out enabling that setting of my server.


回答1:


You can use CURL to open remote resources.

$curlHandler=curl_init();

curl_setopt($curlHandler, CURLOPT_URL, "http://youurl.com");

curl_setopt($curlHandler, CURLOPT_HEADER,0);

curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);

$output =curl_exec($curlHandler);

....

curl_close($curlHandler);



回答2:


Honestly, your best bet is going to finding another way to generate PDFs. FPDF has had only one update since 2004, and no longer seems to be actively maintained.

Some other pure-PHP options include TCPDF and Zend_PDF, both of which seem to be actively maintained and supported.

You should also give some consideration to other PDF generation techniques. For example, there are quite a few HTML-to-PDF converters, some commercial, some open source. wkhtmltopdf, for example, uses the WebKit rendering engine (the one that Safari and Chrome use) to create PDFs.




回答3:


I had similar problem, the fix for it without setting allow_url_fopen on was 1. move the image to the server hosting the script 2. assume the image is imagefile.gif inside a folder called images 3. access the image in my script doing this $_SERVER['DOCUMENT_ROOT']."images/imagesfile.gif"



来源:https://stackoverflow.com/questions/3272037/fpdf-issue-while-generating-pdf-with-images-due-to-php-allow-url-fopen-setting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!