[ir a la versión en castellano]
I received several queries regarding the problem of creating a PDF with images in some servers where the value of the “allow_url_fopen” is set Off in php.ini configuration file.
The classes html2fpdf uses fopen to open the images in the html source that we use to create the PDF and in the cases just commenting will not work correctly. Ie, the images will not appear in the PDF we generate.
The solution is to replace the fopen function for the functions that cURL offers us a platform library that enables the transfer of files from the client side through multiple protocols.
As an example we show a slice of the modified code:
if ( ‘allow_url_fopen’ == ‘Off’)
$ f = fopen ($ file, ‘rb’);
Open with //—– Curl
$ curl_handler = curl_init ();
curl_setopt ($ curl_handler, CURLOPT_URL, $ file);
curl_setopt ($ curl_handler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ curl_handler, CURLOPT_BINARYTRANSFER, 1);
$ f = curl_exec ($ curl_handler);
curl_close ($ curl_handler);
I hope you are helpful.