Re: using fopen() in write mode is failing



On May 31, 2:08 am, Lawrence Krubner <lawre...@xxxxxxxxxxx> wrote:
cscor...@xxxxxxxxx wrote:
On May 30, 3: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?

Actually, I think it must have something to do with the way this
particular webserver is setup (be it apache/php), because it works
fine when tested on another server (not maintained by me).

It's true. Is there any chance you've an older version of PHP installed,
some version from before the "b" flag was introduced? Have you tried:

fopen($file,"w")

just to see what would happen?

I've tried all modes that include writing options (r+, w+, a, etc),
and none of them seem to work. The PHP verion is 5.2.5, and reflects
that when I do phpinfo(). The server in question is Fedora9 with php/
apache installed via yum from the repos, and both have nearly default
settings.
.



Relevant Pages