Gil*_*erg 1 php shell command-line wkhtmltopdf
我在Mac OS X 10.9.4上
我可以从命令行成功运行此命令以生成图像或google.com
wkhtmltoimage http://www.google.com /Users/me/Sites/google.jpg
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用php命令从我的网站内执行相同的命令时
$cmd='wkhtmltoimage http://www.google.com /Users/me/Sites/google.jpg';
shell_exec($cmd);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
sh: wkhtmltoimage: command not found
Run Code Online (Sandbox Code Playgroud)
这是许可问题吗?如果是这样我怎么能让它工作?
====
我设置了像@Mureinik建议的完整路径,我现在取得了一些进展,我得到的错误信息是
Loading page (1/2)
[> ] 0%
[======> ] 10%
[=============> ] 23%
[==================> ] 31%
[===================> ] 33%
[========================> ] 41%
[=====================================> ] 62%
[=======================================> ] 65%
[========================================> ] 67%
[=========================================> ] 69%
[==========================================> ] 71%
[==============================================> ] 78%
[==================================================> ] 84%
[===================================================> ] 86%
[============================================================] 100%
Rendering (2/2)
[> ] 0%
[===============> ] 25%
Error: Could not write to output file
Error: Could not save image
[============================================================] 100%
Done
Exit with code 1, due to unknown error.
Run Code Online (Sandbox Code Playgroud)
我现在有权限问题吗?
====
我将文件权限更改为目的地,并将其处理完毕.
问题可能是shell_exec使用了与$PATH你不同的,因而无法定位wkhtmltoimage.从您自己的shell,您可以使用它which wkhtmltoimage来确定它的安装位置,然后使用shell_exec完整路径,例如:
$cmd='/opt/wkhtmltoimage http://www.google.com /Users/me/Sites/google.jpg';
shell_exec($cmd);
Run Code Online (Sandbox Code Playgroud)