简体   繁体   中英

TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/

I have a website that is generating a PDF file based from data.

I tried it in a free webhost and it is ok but when i upload it to my server i get this error:

TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/mska_1d34cb1ba2c1951624fbccb7556c6d1d

in the cache folder the mska_1d34cb1ba2c1951624fbccb7556c6d1d doesnt exist in the folder.

I got the answer now.

For all who will be able to encounter this problem these are the possible solution.

One cause is that folders inside tcpdf has no permissions of write and read. make sure the folder for cache and images has 644 or 755 (recommended) permission. these permission is very important because there is a process when generating pdf it write something is the cache or read into images.

another cause is that tcpdf does not accept png file or with transparent images. my solution was to make the image into a jpeg and apply a white background for it. so avoid png with transparent.

hope it helped.

In Ubuntu this error was fixed by setting 777 permissions on the tcpdf/cache/ folder:

chmod 777 cache

I tried with 755 or 775 and did not work.

At a guess (with a name like that), it's trying to WRITE to that folder. Check PHP/Apache has write permissions to that folder.

It'll also want to read from it later as well, so give read and write permissions.

In addition to Bert's recommendation to check the folder permissions, check for HTTP/HTTPS issues, and note that you can set the K_PATH_MAIN server path to the tcpdf folder if it's not being automatically calculated correctly. (in tcpdf_config.php)

define ('K_PATH_MAIN', '/my/absoulte/path/tcpdf/');

just create a folder named cache from the library folders TCPPDF

where there are config folders, fonts and images, also create a cache folders and give permission 777 or 755 if not work.

This issue can also be caused by enforcing SELinux. An exception needs to be added. Can be easily tested with setenforce 0, and then retry to produce the pdf.

Check that your files have extension of pdf (all lower case) and not PDF (all caps). Or make them consistent one way or another. I had this issue between Windows / Linux systems.

在我的情况下,该文件受到保护,TCPDF试图用CURL(!?!?)获取该图像,并且它收到403错误,因为Apache没有找到正确的cookie。

我用图像的绝对路径修复了替换url http://www.example.com/img1.jpg /home/image/img1.jpg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM