Problem with tcpdf - Import an image

2

I am creating a pdf from html

require_once('tcpdf/tcpdf.php'); 
.....
$content .='img src="/img.png" width="50" height="50">'    
$obj_pdf->writeHTML($content,true, 0, true, 0);  
$obj_pdf->Output('sample.pdf', 'I');

But this error appears to me

  

Warning: imagecreatefrompng (/img/img.png): failed to open stream: No   such file or directory in ......... \ page-template \ tcpdf \ tcpdf.php on   line 7033

The file and the image are in the page-template folder but the image is looking for the tcpdf folder.

    
asked by julix1994 09.08.2018 в 21:31
source

1 answer

0

Surely the / of the route is looking for it from where it is called, in this case, from the TCPDF folder. What you could do is pass the full path of the image:

$pathImg = realpath('../page-template/img.png'); 
$content .='img src="'.$pathImg.'" width="50" height="50">'    
$obj_pdf->writeHTML($content,true, 0, true, 0);  
$obj_pdf->Output('sample.pdf', 'I');

Within realpath you will have to write the relative path from where your php is located.

Since I do not know at what level you have the image from the php, you'd better check that /page-template/img.png is the correct route.

    
answered by 10.08.2018 в 16:45