我想在文件test1.php
中执行php文件test.php
。我的问题是当我在服务器(test.php
)的终端中手动运行脚本php /home/users/xh/*****/WWW/BP/test.php
时,它将完成工作并执行test1.php
。但是当我在浏览器中打开test.php
时,它不会执行test1.php
。我在文件夹和.php文件中添加了+ x权限,但它无论如何都不起作用 - ls -ld : drwxr-xr-x
,ls -l: -rwxr-xr-x
(在test1和test上)
以下是test.php
:
<?php
echo "including test1\n";
exec('php -f /home/users/xh/*****/WWW/BP/test1.php');
echo "end";
test1.php
:
<?php
$db = mysql_connect('localhost:/var/run/mysql/mysql.sock', '*******', '*******');
if (!$db) die('cannot connect'.mysql_error());
if (!mysql_select_db('******', $db)) die('db not available '.mysql_error());
$var=mysql_set_charset("UTF8", $db);
if (!($result = mysql_query("INSERT INTO table VALUES ('abcdefg','100','20','3','3')", $db))) {
echo "insert not successful";
}
else
echo "insert successful";
编辑:当test1.php
运行脚本shell_exec()
时,它会显示此警告:
Warning: shell_exec() [function.shell-exec]: Cannot execute using backquotes in Safe Mode