我试图用php中的fopen打开一个文件。
$db_ausgaenge = "statuseing.php";
$dout = fopen($db_ausgaenge, "x+");
print $dout;
print(shell_exec('whoami'));
print(shell_exec('pwd'));
print(shell_exec('id'));
fwrite($dout, $out);
fclose($dout);
Warning: fopen(statuseing.php): failed to open stream: File exists in /var/www/html/zufallsgenerator.php on line 33
我检查了以下项目:
在phpinfo()中显示的php.ini中检查了openbase目录,添加了/ var / www / html,但php并不关心它。
open_basedir = / var / www / html /
守护进程重新加载并通过systemctl重新启动apache2后没有任何改变,phpinfo()没有显示配置中给出的路径。通过init 6重启系统也没有生效。
答案 0 :(得分:1)
答案 1 :(得分:1)
statuseing.php已经存在。
请参阅手册(http://php.net/manual/en/function.fopen.php) - 以x或x +模式打开说:Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE
答案 2 :(得分:0)
试试这个:
$db_ausgaenge = __DIR__."/statuseing.php";
$dout = fopen($db_ausgaenge, "a+"); // x+ will throw error cuz it tries to open existing file, thx to: bluegman991 (;
print(shell_exec('whoami'));
print(shell_exec('pwd'));
print(shell_exec('id'));
fwrite($dout, $out);
fclose($dout);
或者如果您想在添加数据之前截断文件,请使用w+
:
$db_ausgaenge = __DIR__."/statuseing.php";
$dout = fopen($db_ausgaenge, "w+");
print(shell_exec('whoami'));
print(shell_exec('pwd'));
print(shell_exec('id'));
fwrite($dout, $out);
fclose($dout);
也做一些检查:
1)检查可用空间:df -h
2)检查您是否可以编辑该文件:nano /var/www/html/statuseing.php