PHP 无法读取文件

标签 php linux raspberry-pi fopen

我无法尝试在 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/

相关文章:

php - Laravel 验证 : only allow known properties/attributes, 否则验证失败

linux - Qmake - 不在 Linux 中复制文件

linux - 如何通过 BlueZ C 库执行蓝牙低功耗扫描

linux - 如何添加新的 Mime 类型并关联到新的应用程序?

PHP 表单无法编辑 MySQL 表数据

php - 有没有办法在Windows上通过PHP利用Oracle钱包?

php - 通过 ANT 获取和使用父目录

linux - 有时在 Raspbian Buster、Raspberry Pi 4 中重新启动时未加载蓝牙模块

python - 如何使用 PIR 传感器将信息从客户端发送到服务器端 [WinError 10057]

python - 即使程序关闭也会递增的变量