簡體   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