由于PHP的'allow_url_fopen'设置,在生成带有图像的pdf时出现了FPDF问题[英] FPDF issue while generating pdf with images due to PHP 'allow_url_fopen' setting

本文是小编为大家收集整理的关于由于PHP的'allow_url_fopen'设置,在生成带有图像的pdf时出现了FPDF问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正面临FPDF的问题,同时使用here解释的图像生成PDF文件.最后,我找到了这个问题的原因,但我不确定如何解决该问题,任何人都可以建议一些很好的解决方案来处理该问题.

此问题是由于 allow_url_fopen 我的服务器设置的设置,如果我启用该设置,则FPDF库正在生成带有图像的PDF文件,也​​没有任何错误.

我正在为我的客户网站之一使用此FPDF库,他(客户端)由于安全原因而禁用了" allow_url_fopen"设置,并且他没有被插入以启用该设置.如何通过启用服务器设置来解决此问题.

推荐答案

您可以使用Curl打开远程资源.

$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);

其他推荐答案

我也有类似的问题,解决方案的修复 1.将图像移至托管脚本的服务器 2.假设图像是imagefile.gif在一个名为图像的文件夹中 3.访问我的脚本中的图像$ _server ['document_root'].

其他推荐答案

老实说,您最好的选择是寻找另一种生成PDF的方法. FPDF具有自2004年以来只有一个更新,而且似乎不再积极地维护.

其他一些pure-php选项包括 zend_pdf 这两个似乎都得到了积极维护和支持./p>

您还应该考虑其他PDF生成技术.例如,有很多商业,一些开源.例如创建PDFS.

本文地址:https://www.itbaoku.cn/post/2090922.html

问题描述

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.

推荐答案

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

其他推荐答案

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"

其他推荐答案

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.