PHP 无法读取文件
PHP isn't able to read file
我无法尝试在 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
我检查了以下项目:
- chmod statuseing.php 0777
- 所有者是 www-data 和 groud www-data
- 脚本是 运行 作为用户 www-data
- 组是 uid=33(www-data) gid=33(www-data) groups=33(www-data)
- pwd 是 /var/www/html 正如预期的那样
- 脚本要打开的路径是正确的
检查 php.ini 中的 openbase 目录显示在 phpinfo() 中,添加了 /var/www/html,但 php 不关心它。
open_basedir = /var/www/html/
守护进程重新加载并通过 systemctl 重新启动 apache2 后没有任何变化,phpinfo() 没有显示配置中给定的路径。通过 init 6 重启系统也没有生效。
看你用的是什么模式
x+ 表示如果文件已经存在将抛出错误。
要根据您的场景找到正确的模式,请查看 http://php.net/manual/en/function.fopen.php
试试这个:
$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) 免费检查 space: df -h
2) 检查您是否可以编辑该文件:nano /var/www/html/statuseing.php
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
我无法尝试在 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
我检查了以下项目:
- chmod statuseing.php 0777
- 所有者是 www-data 和 groud www-data
- 脚本是 运行 作为用户 www-data
- 组是 uid=33(www-data) gid=33(www-data) groups=33(www-data)
- pwd 是 /var/www/html 正如预期的那样
- 脚本要打开的路径是正确的
检查 php.ini 中的 openbase 目录显示在 phpinfo() 中,添加了 /var/www/html,但 php 不关心它。
open_basedir = /var/www/html/
守护进程重新加载并通过 systemctl 重新启动 apache2 后没有任何变化,phpinfo() 没有显示配置中给定的路径。通过 init 6 重启系统也没有生效。
看你用的是什么模式
x+ 表示如果文件已经存在将抛出错误。
要根据您的场景找到正确的模式,请查看 http://php.net/manual/en/function.fopen.php
试试这个:
$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) 免费检查 space: df -h
2) 检查您是否可以编辑该文件:nano /var/www/html/statuseing.php
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