gpt4 book ai didi

php - Imagick 不打开带有 "Failed to read the file"异常的 pdf 文件

转载 作者:可可西里 更新时间:2023-11-01 12:27:39 32 4
gpt4 key购买 nike

尝试从 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

文件权限没问题。尝试两者,一个 URL 和具有 realpath 功能的本地文件,所以文件路径也可以。如果打开 jpeg,脚本工作正常。

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

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

最佳答案

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

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

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

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

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

关于php - Imagick 不打开带有 "Failed to read the file"异常的 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37927247/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com