转换在shell中,但不在shell_exec中

时间:2014-11-28 19:48:21

标签: php permission-denied imagemagick-convert

似乎有许多相关问题,经过其中许多问题的拖网搜索后,我似乎无法找到解决方案。

在shell中执行以下操作可以解决问题:

/usr/local/bin/convert -trim -density 300 /Users/fullpath/file.pdf /Users/fullpath/file.png

然后在php文件中执行如下操作:

    <?php
    putenv("PATH=/usr/local/bin:/usr/bin:/bin");
    echo shell_exec('/usr/local/bin/convert -trim -density 300 /Users/fullpath/file.pdf /Users/fullpath/file.png  2>&1');
    ?>

没有。显示的错误消息是:

  

convert:UnableToCreateTemporaryFile   `/Users/fullpath/file.pdf':权限被拒绝

我的规格是: Mac:雪豹 通过localhost运行Apache。

显然这是一个权限问题,但在哪里?文件本身和相关文件夹都是777。

1 个答案:

答案 0 :(得分:0)

这看起来很奇怪,但你能尝试设置一个特定的临时性吗?

试试这段代码,我刚刚添加了一个新的环境变量,将临时目录设置为/ tmp(您可以尝试其他位置):

<?php
putenv("PATH=/usr/local/bin:/usr/bin:/bin");
putenv("MAGICK_TEMPDIR=/tmp");
echo shell_exec('/usr/local/bin/convert -trim -density 300 /Users/fullpath/file.pdf /Users/fullpath/file.png  2>&1');
?>