Michael Beckmann Michael Beckmann - 1 year ago 86
Linux Question

PHP isn't able to read file

I'm stuck trying to open a file with fopen in php.

$db_ausgaenge = "statuseing.php";
$dout = fopen($db_ausgaenge, "x+");
print $dout;
fwrite($dout, $out);

Warning: fopen(statuseing.php): failed to open stream: File exists in /var/www/html/zufallsgenerator.php on line 33

I checked following items:

  • chmod for statuseing.php 0777

  • owner is www-data with groud www-data

  • script is running as user www-data

  • groups are uid=33(www-data) gid=33(www-data) groups=33(www-data)

  • pwd is /var/www/html as expected

  • the path the scripts want's to open is correct

  • checked openbase dir in php.ini showed in phpinfo(), added /var/www/html, but php doesn't care about it.

    open_basedir = /var/www/html/

After daemon-reload and restarting apache2 via systemctl nothing changed, phpinfo() didn't show the path given in the config. restarting the system via init 6 didn't took effect, too.

Answer Source

statuseing.php already exists.

See the manual (http://php.net/manual/en/function.fopen.php) - opening in x or x+ mode says: 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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download