【发布时间】:2011-10-17 14:41:21
【问题描述】:
我有一个 PHP 脚本,它使用 wget 下载一些图像。但是,wget 是使用 Homebrew 安装的,因此运行 PHP 脚本的用户无法使用它。当我运行exec('echo $PATH') 时,我没有得到包含wget 的/usr/local/bin 目录。如何将/usr/local/bin 添加到环境路径中,以便PHP 脚本可以找到wget?
更新:我忘了提到我无法指定确切位置的原因是因为该位置可能会因运行此脚本的机器而异。
解决方案:
这就是我最终的结果:
//help PHP find wget since it may be in /usr/local/bin
putenv('PATH=' . getenv('PATH') . PATH_SEPARATOR . '/usr/local/bin');
if (exec('which wget') == null) {
throw new Exception('Could not find wget, so image could not be downloaded.');
}
//now we know wget is available, so download the image
exec('wget ...');
【问题讨论】:
标签: php path environment-variables