|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31059 cannot write to files
Submitted: 2004-12-10 23:22 UTC Modified: 2004-12-11 00:38 UTC
From: gagarin at i-dep dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.9 OS: linux fedora core 3
Private report: No CVE-ID: None
 [2004-12-10 23:22 UTC] gagarin at i-dep dot com
I cannot open files for writing with fopen. fileperms function on existing file returns FALSE.

i checked file permissions, turned safe mode off to no avail. the same script runs on machines with  FC1 and php 4.3.8 just fine.

fopen for reading works fine.

I can read/write the same files with perl cgi scrips but not with php 

Reproduce code:
my test script

$filename = '/var/www/html/test.txt';
$content = "Add this to the file\n";

if (file_write($filename,$content)) echo "Success";

   function file_write($filename, &$content) {

     if (!$fp = @fopen($filename, "w")) {
           echo "Cannot open file ($filename)";
       if (fwrite($fp, $content) === FALSE) {
           echo "Cannot write to file ($filename)";
       if (!fclose($fp)) {
           echo "Cannot close file ($filename)";

    return true;


Expected result:

Actual result:
Cannot open file (/var/www/html/test.txt)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-11 00:38 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 04:01:24 2020 UTC