代码之家  ›  专栏  ›  技术社区  ›  Siva

FPDF错误:图像文件丢失或不正确

  •  2
  • Siva  · 技术社区  · 16 年前

    FPDF error: Missing or incorrect image file:{MY_FILE_PATH} 在尝试将图像添加到我的PDF页面时。通过浏览器访问该文件路径,则相应的图像显示良好。

    我的代码是:

    require('fpdf.php');
    
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Write(10, 'Example image');
    $image_path = MY_FILE_PATH; // This variable contains my actual file path 
    $pdf->Image($image_path, 10, 10, 350, 450);
    $pdf->Output();
    

    我尝试过这些可能性,比如:

    1. 具有图像的绝对和相对路径。

    2. 尝试将本地图像放在同一文件夹中。

    3. 所有图像格式,如jpg,png和gif也。

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  5
  •   Community Mohan Dere    9 年前

    经过长期的斗争,我终于找到了我已经讨论过的这个问题的原因 here .

    这个问题主要是由于“allow\u url\u fopen”设置没有为我的服务器启用,我已经通过使用CURL解决了这个问题。我给出了解决这个问题的一步一步的程序,因为这对像我这样的人来说可能有用,可以避免浪费时间(找到解决方案)。

    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.
    
    

    我认为这是一个解决这个问题的方法,如果有人知道一些其他的方法,那么你可以把它们贴在这里,这样这个问题可能对某人有用。

        2
  •  2
  •   user1638334    13 年前

    只需添加:

    允许打开

    在php.ini上(如果不存在,则创建新的)解决了这个问题。

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

        3
  •  0
  •   pankaj kumar    5 年前

    任何人都可以使用此代码来解决。也许会有用。因为有些情况可能会不同。在我的情况下,我得到了同样的问题,但使用后。我解决了我的问题。。

    $pdf->Image($image_path, 10, 10, 350, 450 ,''); 
    

    $pdf->图像() 函数,也可以指定文件扩展名,如(PNG或JPG)。对我来说 '' 他在工作。因为我在裁剪图像,所以图像有时会出错。所以在那之后,我的问题得到了解决,我用不同的图像进行了测试。

    推荐文章