Hallo,

I am trying to write a string to a text file but I cannot connect to the file with the 'w' mode.

It seems like 'r' mode only is accepted but I cannot find how to write/create new content to the file.

I am using PHP 4.2.2, Apache 2, on a Linux server.

The code I am trying is:

$file = '/server_path/file.txt';

if(!$fd = fopen($file, "w")) {
echo 'unable to open file'; //this is what I get
exit;
}

if(fwrite($fd, $string) === FALSE) {
echo 'unable to write to file';
exit;
} else {
echo 'I wrote '.$fout.' chars.';
}
fclose($fd);

Could anybody help ?

Thank you !

    Dou you set write access to the file (on your server?)

      Well, I was supposing that 'w' mode could create the file with right permissions... but I don't know...

      Anyway I have tryed to run the same script from the linux command prompt and it has worked !

      While it is not working if I call it from a browser...

      I don't know why...

        If you work from the command prompt then have the rights from the root. Check the access rights of the map.

          Write a Reply...