转换在shell中,但不在shell_exec中

There seem to many related questions and after trawling through many of them I still cannot seem to find a solution.

Executing the following in a shell does the trick:

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

yet doing it in a php file as follows:

    <?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');
    ?>

doesn't. The error message displayed is:

convert: UnableToCreateTemporaryFile `/Users/fullpath/file.pdf': Permission denied

My specs are: Mac: snow leopard Running Apache, through localhost.

Obviously it is a permissions problem, but where? The file itself and associated folders are all at 777.

this seems very odd, but can you try setting a specific temporary?

Try this code, where I just added a new environment variable setting the temporary dir to /tmp (you can try another locations):

<?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');
?>