HTML2PDF Image Error Impossible to Load the Image

倖福魔咒の 提交于 2019-12-10 14:09:51

问题


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

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

Impossible to load the image /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.

     <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

Please help!!

Thank You


回答1:


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

   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.




回答2:


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.

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



回答3:


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

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

I had to enable allow_url_fopen on the server



来源:https://stackoverflow.com/questions/20390284/html2pdf-image-error-impossible-to-load-the-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!