如何在PHP中设置$ PATH? [英] How to set $PATH in PHP?

查看:129
本文介绍了如何在PHP中设置$ PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理自己的小项目,但是我有一个小问题:我想将$ PATH环境变量设置为 ./ bin ,这样当我使用 exec()和类似的函数,它只会搜索该目录中的二进制文件(除非我明确地另有说明)。



我已经尝试过 putenv(),除非我启用了安全模式,否则这将不起作用,我不想这样做;我也尝试过 apache_setenv(),但似乎也没有起作用。



有没有其他解决方案我可能想尝试?



(我正在使用带有PHP 5.3.2的Linux机器)

解决方案

如果您只想在特定情况下设置,可以执行以下操作:

  exec (PATH = / my / path ./bin); 


I am currently working on my own little project, but I have a little problem: I want to set the $PATH environment variable to ./bin, so that when I use exec() and similar functions, it would only search for binary files in that directory (unless I explicitly tell it otherwise).

I have already tried putenv(), which won't work unless I have safe-mode enabled, which I'd prefer not to; and I also tried apache_setenv(), but that didn't seem to work either.

Are there any other solutions I might want to try?

(I am using a Linux machine with PHP 5.3.2)

解决方案

If you want to set it only in specific circumstances, you can do:

exec("PATH=/my/path ./bin");

这篇关于如何在PHP中设置$ PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆