php 无法加载图像的 HTML2PDF 图像错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20390284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:08:34  来源:igfitidea点击:

HTML2PDF Image Error Impossible to Load the Image

phphtmlpdfconverterhtml2pdf

提问by user1109244

I am using HTML2PDF and I am trying to make images appear but I keep on getting this error:

我正在使用 HTML2PDF 并且我正在尝试显示图像,但我一直收到此错误:

ERROR n?°6 File : /var/www/vhosts/default-domain.com/httpdocs/html2pdf_v4.03/html2pdf.class.php Line : 1321

错误 n?°6 文件:/var/www/vhosts/default-domain.com/httpdocs/html2pdf_v4.03/html2pdf.class.php 行:1321

Impossible to load the image /student/questions 3rd/images/small1324538668Number Lines 5.JPG

无法加载图片/student/questions 3rd/images/small1324538668Number Lines 5.JPG

Can anybody please help me with this issue? I have been struggling with it for a while already.

有人可以帮我解决这个问题吗?我已经为此苦苦挣扎了一段时间。

This is the html code that I have.

这是我拥有的 html 代码。

     <img src="/student/questions 3rd/images/small1324538668Number Lines 5.JPG" />

And here is the site to check to see how it works.

这是检查它如何工作的站点。

http://www.domain.com/html2pdf_v4.03/examples/Test.php

http://www.domain.com/html2pdf_v4.03/examples/Test.php

Please help!!

请帮忙!!

Thank You

谢谢你

回答by Neeraj Kumar

While using HTML2PDF yo have to give the full path of your image like in this manner

在使用 HTML2PDF 时,您必须以这种方式提供图像的完整路径

   http://domain/path/to/image 

or you can give student/questions 3rd/images/small1324538668Number Lines 5.JPG because any script runs on base of index.php which is located in root so you have to give the image path from root location.

或者你可以给学生/问题 3rd/images/small1324538668Number Lines 5.JPG 因为任何脚本都运行在位于根目录的 index.php 的基础上,所以你必须从根位置提供图像路径。

回答by Shareful

HTML2PDF failed to load image on image src when allow_url_fopen is not enabled in the server. There is another solution who have not access to enable allow_url_fopen. Solution is to use image base64 encoded data as image source. Example code below.

当服务器中未启用 allow_url_fopen 时,HTML2PDF 无法在图像 src 上加载图像。还有另一个解决方案无法启用allow_url_fopen。解决方案是使用图像base64编码数据作为图像源。下面的示例代码。

<?php
 $path =  'directory/example.jpg';
 $type = pathinfo($path, PATHINFO_EXTENSION);
 $data = file_get_contents($path);
 $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
?>
<img src="<?php echo $base64 ?>">

回答by Brett Gregson

In my case, my image src attribute was an absolute path and it still wasn't working:

就我而言,我的图像 src 属性是绝对路径,但仍然无法正常工作:

<img src="http://example.com/image.jpg"/>

I had to enable allow_url_fopenon the server

我必须allow_url_fopen在服务器上启用