php TCPDF 错误:无法打开图像文件:/var/www/html/tcpdf/cache/
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10782329/
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
TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/
提问by Bert
I have a website that is generating a PDF file based from data.
我有一个根据数据生成 PDF 文件的网站。
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
TCPDF 错误:无法打开图像文件:/var/www/html/tcpdf/cache/mska_1d34cb1ba2c1951624fbccb7556c6d1d
in the cache folder the mska_1d34cb1ba2c1951624fbccb7556c6d1d doesnt exist in the folder.
在缓存文件夹中,文件夹中不存在 mska_1d34cb1ba2c1951624fbccb7556c6d1d。
回答by Bert
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.
原因之一是 tcpdf 中的文件夹没有读写权限。确保缓存和图像文件夹具有 644 或 755(推荐)权限。这些权限非常重要,因为在生成 pdf 时有一个过程,它写入一些内容是缓存或读入图像。
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.
另一个原因是 tcpdf 不接受 png 文件或透明图像。我的解决方案是将图像制作成 jpeg 并为其应用白色背景。所以避免透明的png。
hope it helped.
希望它有所帮助。
回答by Edgar Ortega
In Ubuntu this error was fixed by setting 777 permissions on the tcpdf/cache/folder:
在 Ubuntu 中,通过在tcpdf/cache/文件夹上设置 777 权限来修复此错误:
chmod 777 cache
I tried with 755 or 775 and did not work.
我用 755 或 775 尝试过,但没有用。
回答by Robbie
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.
猜测(使用类似的名称),它正在尝试写入该文件夹。检查 PHP/Apache 对该文件夹的写入权限。
It'll also want to read from it later as well, so give read and write permissions.
稍后它也想从中读取数据,因此请授予读取和写入权限。
回答by squarecandy
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)
除了 Bert 建议检查文件夹权限,检查 HTTP/HTTPS 问题之外,请注意,如果未正确自动计算,您可以将 K_PATH_MAIN 服务器路径设置为 tcpdf 文件夹。(在 tcpdf_config.php 中)
define ('K_PATH_MAIN', '/my/absoulte/path/tcpdf/');
define ('K_PATH_MAIN', '/my/absoulte/path/tcpdf/');
回答by user2217518
just create a folder named cache from the library folders TCPPDF
只需从库文件夹 TCPPDF 创建一个名为缓存的文件夹
where there are config folders, fonts and images, also create a cache folders and give permission 777 or 755 if not work.
如果有配置文件夹、字体和图像,还可以创建一个缓存文件夹,如果不起作用,则授予权限 777 或 755。
回答by user3081471
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.
此问题也可能是由强制执行 SELinux 引起的。需要添加一个例外。可以使用 setenforce 0 轻松测试,然后重试生成 pdf。
回答by Dennis
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.
检查您的文件是否具有 pdf 扩展名(全部小写)而不是 PDF(全部大写)。或者以某种方式使它们保持一致。我在 Windows / Linux 系统之间遇到了这个问题。
回答by Bobby Tables
In my case, the file was protected and TCPDF tried to get that image with CURL (!?!?) and it got a 403 error, because Apache did not find the right cookie.
就我而言,文件受到保护,TCPDF 尝试使用 CURL (!?!?) 获取该图像,但出现 403 错误,因为 Apache 没有找到正确的 cookie。
回答by Sahaya Thivearaj
I fixed replacing url http://www.example.com/img1.jpgwith absolute path of the image /home/image/img1.jpg
我修复了用图像的绝对路径 /home/image/img1.jpg替换 url http://www.example.com/img1.jpg

