我正在使用 PHP 的 exec()
使用 ImagicMagick 的 convert
转换图像。这是在 CentOS 服务器上运行的。
exec(convert http://www.google.com/images/srpr/logo3w.png.jpg
-resize 640 /home/mysite/public_html/public/img/posts/original/1414_301a4.jpg);
使用 exec()
不会导致新图像出现在目标文件夹中。但是,如果我要在 shell 中运行相同的命令,它会完美运行!
我相信这是一个 PATH 问题。如果是这样,我如何检查 PHP 使用的路径,以及如何在 PHP 中设置正确的路径?
最佳答案
function execute($command)
{
# remove newlines and convert single quotes to double to prevent errors
$command = str_replace(array("\n", "'"), array('', '"'), $command);
# replace multiple spaces with one
$command = preg_replace('#(\s){2,}#is', ' ', $command);
# escape shell metacharacters
$command = escapeshellcmd($command);
# execute convert program
return shell_exec($command); // or whatever you like
}
关于php - ImageMagick convert 在命令行中工作,但不能通过 PHP exec(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12061170/