Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF cant image because it is using a wrong directory path

Tags:

php

pdf

tcpdf

I get my images in my pdf document on my localhost but on the production site i get the error TCPDF ERROR: [Image] Unable to get image i am using an html img tag to get the images and the src is the directory path to this image not a url, but i found out that TCPDF is adding the path i give it with the path to my www folder like:

path to picture i give to tcpdf: home/inc_dir/img/pic.jpg
tcpdf looks for it here: home/www/home/inc_dir/pic.jpg

can someone please help me find out tcpdf is concatenating the directories?

like image 364
Ogie Avatar asked Feb 23 '12 14:02

Ogie


2 Answers

You can also change only the image path instead of main path use:

define('K_PATH_IMAGES', '/path/to/images/');
require_once('tcpdf.php');

This won't break fonts/ and other tcpdf paths.

like image 161
ghi Avatar answered Nov 05 '22 13:11

ghi


TCPDF is using $_SERVER['DOCUMENT_ROOT'] as a root directory of all your images, and builds their absolute paths in relation to it. You can change it either in $_SERVER or with this PHP constant: K_PATH_MAIN:

define('K_PATH_MAIN', '/path/to/my-images/');
require_once 'tcpdf.php';
like image 7
yegor256 Avatar answered Nov 05 '22 12:11

yegor256