Re: using fopen() in write mode is failing



On May 30, 9:08 pm, cscor...@xxxxxxxxx wrote:
For some reason, I cannot use fopen() on the file in write mode. The
file "time" is in the same directory as the .php file, with
permissions set to 0766.

PHP Version 5.2.5
Apache/2.2.8

code snip in question:

$file = "time";
function updateParseTime($name){
        global $file;
        if (file_exists($name) && file_exists($file)) {
                if(($fp = fopen($file,"wb"))){
                        $lastmod = filemtime($name);
                        if(!(fwrite($fp, $lastmod))){
                                echo "cannot update time";
                        }
                }
                else{
                        echo "$file cannot be opened. \n";
                }
        }
        else{
                echo "$name or $file not found.";
        }

}

on the 4th line it fails the if check ($fp = fopen...) and just
outputs "$file cannot be opened"

Am I missing something?

Is error reporting on? If it is then PHP will echo out its own error
message in addition to yours. Did you originally create the file
you're trying to write to or was it created via a PHP script? If the
former is the case then it will have you as the owner. PHP runs as the
webserver's user (something like www or apache or nobody, assuming
you're using PHP in a webserver environment). This will mean a
permission denied error occurs when you try to open the file. Try
setting the file to 666 chmod, or chown it to the Apache process's
user.
.



Relevant Pages