简体   繁体   English

如何使Shell命令与exec在php中一起工作

[英]How to get a shell command to work in php with exec

When I run in a terminal: 当我在终端中运行时:

convert file.pdf file.png

everything works fine, but when I do this in a php script as: 一切正常,但是当我在php脚本中这样做时:

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

I get errors. 我得到错误。 When I search online how to solve these errors I end up making subtle changes to files here, and permissions there. 当我在线搜索如何解决这些错误时,最终对这里的文件和那里的权限进行了细微的更改。 The errors change and I have no idea how I got to where I am. 错误改变了,我不知道如何到达自己的位置。 I feel as though I am chasing a phantom. 我感觉好像在追逐幻影。

I don't know whether the problem lies with imagemagick, php, ghostscript, permissions, etc. 我不知道问题是否出在imagemagick,php,ghostscript,权限等方面。

So my question is: How should I go about so that I can re-attack this problem from the beginning? 所以我的问题是:我应该怎么做才能从一开始就重新解决这个问题? Do I need to reinstall things? 我需要重新安装东西吗? If so, what and on what order? 如果是这样,什么顺序? What should have what permissions? 什么应该有什么权限?

I appreciate that my question is rather open, but judging by the multitude of similar questions, with all sorts of different answers, it would be good to have some clear definite checklist to work through. 我很欣赏我的问题很开放,但是从众多类似问题以及各种各样不同的答案来看,最好有一些明确的清单来解决。

For completeness I am using mac osx, Yosemite; 为了完整起见,我使用的是Mac osx,优胜美地; php 5.5.27; PHP 5.5.27; ImageMagick 6.9.1-10; ImageMagick 6.9.1-10; gs 9.16 and the present error says: gs 9.16,当前错误提示:

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

I am also using full path names for the convert and the files too. 我也使用转换和文件的完整路径名。

With 'shell_exec' I get more error messages: 使用“ 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.

请注意,PHP的shell_exec带有字符串参数:

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

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

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