如何使用exec获取shell命令在php中工作

时间:2015-09-30 18:26:15

标签: php macos shell imagemagick

当我在终端跑步时:

convert file.pdf file.png

一切正常,但当我在php脚本中执行此操作时:

exec('convert file.pdf file.png');

我收到错误。当我在线搜索如何解决这些错误时,我最终会对这里的文件进行微妙的更改,并在那里进行权限。错误发生了变化,我不知道自己到底是怎么回事。我觉得好像在追逐一个幽灵。

我不知道问题是否与imagemagick,php,ghostscript,权限等有关。

所以我的问题是:我应该怎么做才能从头开始重新解决这个问题?我需要重新安装吗?如果是这样,什么和什么顺序?什么应该有什么权限?

我很欣赏我的问题相当开放,但从众多类似的问题来看,有各种不同的答案,最好有一些明确的明确清单来处理。

为了完整性我正在使用mac osx,Yosemite; php 5.5.27; ImageMagick 6.9.1-10; gs 9.16和目前的错误说:

convert: no images defined `file.png' @ error/convert.c/ConvertImageCommand/3230.

我也在使用转换和文件的完整路径名。

使用'shell_exec'我收到更多错误消息:

dyld: Library not loaded: /usr/local/lib/libtiff.5.dylib 
Referenced from: /usr/local/bin/gs  
Reason: Incompatible library version: gs requires version 8.0.0 or later, but libtiff.5.dylib provides version 6.0.0

convert: FailedToExecuteCommand `"gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE - dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r300x300"  "-sOutputFile=/var/tmp/magick-9254642RiQMO2CuWM%d" "-f/var/tmp/magick-92546j8PosqIIrra3" "-f/var/tmp/magick-92546LB13giWos7rr"' (-1) @ error/delegate.c/ExternalDelegateCommand/483.

convert: no images defined `file.png' @ error/convert.c/ConvertImageCommand/3230.

1 个答案:

答案 0 :(得分:0)

请注意,PHP的shell_exec采用字符串参数:

shell_exec('convert file.pdf file.png');