Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

php - mPDF not rendering images (mPDF error: IMAGE Error Could not find image file)

We are getting plagued with this which started in April on working server. Everything was fine with our application until the customer reported that PDFs were no longer displaying the images.

Our PDF is generated via a HTML render first. When the HTML render is displayed the Image shows correctly. Also the image shows correctly if the image URL as noted in the mPDF is copied and pasted into a new tab.

However... If we load the image from a DIFFERENT DOMAIN then the image is rendered correctly. loading the image via absolute path, relative path or URL path all result in this error:

mPDF error: IMAGE Error (http://www.aibsonline.co.uk/logo.gif): Could not find image file

But, as you will see the logo url works when pasted. File permissions have been tested (which is why it is in the root) as standard and up to 777. Server is a Linux server in both cases we have seen so far.

HTML Code that renders the logo:

<div id="logo_wrapper" class="left">
<img width="107" height="76" src="<?php echo base_url('logo.gif'); ?>" />
</div>

At a real loss with this one and it is beginning to affect more and more clients.

Any help gratefully received.

UPDATE

The image renders if the rendering code and the image are in the same directory and we do NOT use an absolute path, eg.

<img width="107" height="76" src="logo.gif" />
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I ran across this issue today. My problem was that the domain name I was using didn't resolve back to the server when accessed from the server. I added an entry to the hosts file on the server, and images started showing.

Your equivalent hosts file entry of what fixed my problem would be:

127.0.0.1 www.aibsonline.co.uk

Or otherwise ensure that www.aibsonline.co.uk resolves to your server in the DNS that your server uses.

It appears that mPDF accesses images as a cURL web client, so DNS on the server needs to be configured correctly to refer back to itself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...