当我在终端中使用eps
将svg
转换为inkscape
时,它可以正常工作。但是,当我使用php的shell_exec
执行相同的命令时,它不起作用。 (我也尝试过exec
和system
,但没有运气)
示例代码:
<?php
unlink('./sample.svg');
$file_path = realpath('./sample.eps');
$dest_path = getcwd() . '/sample.svg';
//# inkscape --file=sample.eps --export-plain-svg=sample.svg
// command works fine in terminal but not in php
$command = "inkscape --file=$file_path --export-plain-svg=$dest_path";
// command fails with no output (null)
$output = shell_exec($command);
var_dump($output);
var_dump(is_file('./sample.svg'));
同一命令也可以从php shell正常工作!我无法确定原因,因为我无法检查输出(它始终为null)
[ai -> svg
和pdf -> svg
的转换效果很好
我怀疑这是与command works fine through terminal but not shell_exec php类似的问题,但是对这种情况的解决方案是什么?
PS:我正在使用this sample eps file进行测试
编辑:我在2>&1
命令中添加了shell_exec
,并获得了此输出
/srv/www/git/presta17_designer/eps/sample.eps:1: parser error : Start tag expected, '<' not found
%!PS-Adobe-3.0 EPSF-3.0
^
/srv/www/git/presta17_designer/eps/sample.eps:1: parser error : Start tag expected, '<' not found
%!PS-Adobe-3.0 EPSF-3.0
^
** (inkscape:717): WARNING **: 14:16:21.492: Specified document /srv/www/git/presta17_designer/eps/sample.eps cannot be opened (does not exist or not a valid SVG file)
我猜想权限。
PHP-shell可能有效,因为它在您的本地用户下运行。
检查您的Web服务器或PHP会话正在哪个用户下运行,并尝试与该用户一起在Terminal中运行Inkscape,以查看是否允许该操作。如果没有,请添加必要的权限。