试图从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注意! /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