我无法尝试在 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
我检查了以下项目:
- statuseing.php 0777 的 chmod
- owner is www-data with groud www-data
- 脚本作为用户 www-data 运行
- 组是 uid=33(www-data) gid=33(www-data) groups=33(www-data)
- pwd 是预期的/var/www/html
- 脚本要打开的路径是正确的
检查 php.ini 中显示在 phpinfo() 中的 openbase 目录,添加/var/www/html,但 php 不关心它。
open_basedir =/var/www/html/
守护进程重新加载并通过 systemctl 重新启动 apache2 后没有任何变化,phpinfo() 没有显示配置中给定的路径。通过 init 6 重启系统也没有生效。
最佳答案
statuseing.php 已经存在。
请参阅手册 ( http://php.net/manual/en/function.fopen.php ) - opening in x or x+ mode says: Create and open for writing only;将文件指针放在文件的开头。如果文件已经存在,则 fopen() 调用将失败并返回 FALSE
关于PHP 无法读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39947240/