繁体   English   中英

Imagick 不打开带有“无法读取文件”异常的 pdf 文件

[英]Imagick don't open pdf files with “Failed to read the file” exception

尝试从 php 脚本打开 PDF 文件时出现错误:

Uncaught ImagickException: Failed to read the file in ...

我正在运行 OS X、Brew、PHP 7.0、php70-imagick --HEAD、ImageMagick --with-ghostscript、GhostScript

命令行测试工作正常:

convert 1.pdf 1.jpg

文件权限没问题。 尝试使用具有 realpath 功能的 URL 和本地文件,因此 filepath 也可以。 如果打开 jpeg,脚本可以正常工作。

phpinfo() -> ImageMagick supported formats: EPDF, PDF, PDFA, etc.

更新:已解决。 解决方法如下。

这个问题与ghostscript的路径有关。 它位于“/usr/local/bin”中,但该路径对 Apache 不可用。 (phpinfo -> Apache 环境 -> PATH)

解决方案是将文件符号链接到另一个路径:

 sudo ln -s /usr/local/bin/gs /usr/bin/gs

OS X El Capitan 注意! OS X 10.11+ 中的 /usr/bin/ 受到保护。 您必须按照以下步骤操作:

1. Reboot to Recovery Mode. Reboot and hold "Cmd + R" after start sound.
2. In Recovery Mode go to Utilities -> Terminal.
3. Run: csrutil disable
4. Reboot in Normal Mode.
5. Do the "sudo ln -s /usr/local/bin/gs /usr/bin/gs" in terminal.
6. Do the 1 and 2 step. In terminal enable back csrutil by run: csrutil enable

这是在 OS X 上更新 Apache 路径变量的更好方法,它不需要符号链接(因此不需要禁用 SIP):

https://www.euperia.com/wrote/solved-php-imagick-unable-to-open-image-pdf/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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