Search code examples
phpfpdf

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


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.


Solution

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