本文介绍了exec()通过命令行运行,但不通过Web运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个涉及exec()的PHP脚本,可以从命令行正常运行,但不能在Web上下文中运行.脚本就是这样:

I have a PHP script involving exec() that will run fine from the command line but not in a web context. The script is simply this:

<?php exec('echo "wee" > /home/jason/wee.txt');

如果我将此脚本称为wee.php并运行php wee.php,则该脚本可以正常工作,并且wee.txt可以被编写.

If I call this script wee.php and run php wee.php, it works fine and wee.txt gets written.

如果我转至http://mysite.com/wee.php,该脚本会假装运行良好,但实际上wee.txt并未被编写.

If I go to http://mysite.com/wee.php, the script pretends to run fine but wee.txt doesn't actually get written.

知道为什么会这样吗?

推荐答案

Web服务器以其他用户身份运行,并且该用户无权写入您的主目录.

The web server runs as a different user, and that user does not have permission to write to your home directory.

这篇关于exec()通过命令行运行,但不通过Web运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-26 09:26