FPDF error: Missing or incorrect image file

后端 未结 2 1060
夕颜
夕颜 2020-12-18 13:46

I am using the FPDF library for generating PDF files by PHP. This library is working fine with plain text(i.e PDF files are generating for any text), but this is giving me a

相关标签:
2条回答
  • 2020-12-18 13:54

    After a long struggle finally I found the reason for this issue which I've already discussed here.

    Mainly this problem is due to the 'allow_url_fopen' setting which is not enabled for my server, I've solved this issue by using the CURL. I'm giving the step by step procedure to solve this issue because this may useful for somebody like me to avoid wastage of time(for finding the solution).

    1. Create a temporary file in the local system with write permission.
    
    Ex: $fp = @fopen($local_file_path, 'x'); 
        fclose($fp);
    
    2. Get the remote location file contents using CURL and write that to local file 
    which is created in the previous step.
    
    Ex: $curl = new CurlWrapper($remote_file_path);
        $curl->copyToFile($local_file_path);
    
    3. Now send this local file path to FPDF function(image) then the corresponding 
    PDF will get generate for the file without any issues.
    
    

    I think this is one method to solve this issue, if anybody knows some other ways then you can post them here so that this question may be useful for somebody.

    0 讨论(0)
  • 2020-12-18 14:15

    just add:

    allow_url_fopen = ON

    on php.ini (create new if not exists) solves the problem.

    http://www.solo-technology.com/blog/2010/04/07/quick-fix-for-url-file-access-is-disabled-issues/

    0 讨论(0)
提交回复
热议问题