所以我在我的 VPS (Ubuntu 14.04.5) 上安装了 shhavel 的 facerec ( https://github.com/shhavel/facerec ),当我在 putty 中使用它时它工作得很好:
facerec list
jenniferlawrence
emmawatson
但是,在 PHP 中使用 exec() 函数时,唯一有效的命令是 facerec -help,所有其他命令都会产生类似于以下内容的错误:
facerec 列表 2>&1
Traceback (most recent call last):
File "/usr/local/bin/facerec", line 359, in
sys.exit(__main__())
File "/usr/local/bin/facerec", line 356, in __main__
return args.func(args)
File "/usr/local/bin/facerec", line 159, in list
for subject in os.listdir(subjects_directory):
OSError: [Errno 2] No such file or directory: './subjects'
PHP 脚本:
exec('facerec list 2>&1', $output);
foreach($output as $string) {
echo $string."<br>";
}
我该如何解决这个问题?
最佳答案
发现问题:
“subjects”文件夹位于/root/PHP 脚本没有访问权限
可能的解决方案:
- 将 PHP 设置中的 open_basedir 更改为无(参见此处:open_basedir restriction in effect. File(/) is not within the allowed path(s):)
- 以正确的用户身份(不是 root)安装 shhavel/facerec
- 将主题文件夹移动到不同的位置并相应地更改 facerec python 脚本
关于php - 命令在 putty 中工作正常但在 PHP 中不使用 exec(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43760694/