mPDF无法呈现图像(mPDF错误:IMAGE错误找不到图像文件) [英] mPDF not rendering images (mPDF error: IMAGE Error Could not find image file)

查看:651
本文介绍了mPDF无法呈现图像(mPDF错误:IMAGE错误找不到图像文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们对此感到困扰,该问题始于4月在可运行的服务器上.在客户报告PDF不再显示图像之前,我们的应用程序一切正常.

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.

我们的PDF首先通过HTML渲染生成.显示HTML渲染时,图像会正确显示.如果复制了mPDF中提到的图像URL并将其粘贴到新标签中,则该图像也可以正确显示.

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.

但是...如果我们从一个不同的域加载图像,则该图像将正确呈现.通过绝对路径,相对路径或URL路径加载图像都会导致此错误:

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错误:图片错误( http://www.aibsonline.co.uk/logo. gif ):找不到图片文件

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

但是,正如您将看到的,徽标URL在粘贴时会起作用.文件权限已经过标准测试(这就是为什么要在根目录中进行测试),因此最高权限达到了777.到目前为止,在两种情况下,服务器都是Linux服务器.

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代码:

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.

更新

如果渲染代码和图像位于同一目录中,并且我们不使用绝对路径,例如,图像将渲染.

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" />

推荐答案

我今天遇到了这个问题.我的问题是从服务器访问时,我使用的域名无法解析回服务器.我在服务器上的hosts文件中添加了一个条目,并且图像开始显示.

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

否则,请确保www.aibsonline.co.uk在您的服务器使用的DNS中解析为您的服务器.

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

mPDF似乎作为cURL Web客户端访问图像,因此需要正确配置服务器上的DNS以使其返回自身.

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.

这篇关于mPDF无法呈现图像(mPDF错误:IMAGE错误找不到图像文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆