Page 1 of 1

write data to a file wich received from GET

Posted: Wed Jun 02, 2010 4:17 pm
by Rksk
I use this script to Write data to a file wich sent from GET method.
But it doen't write datas with sent as 2nd time.
it writes data the file at only 1st time.

Code: Select all

if (isset($_GET['t'])) {


if (!file_exists("list.html"))
{
  $myFile = "list.html";
  $fh = fopen($myFile, 'w');
  $stringData = "\n";
  fwrite($fh, $stringData);
  fclose($fh);
}

$myFile2 = "list.html";
$fh2 = fopen($myFile2, 'a');
$stringData2 = $_GET['t']."<br> \n <br><p>";
fwrite($fh2, $stringData2);
fclose($fh2);

echo "\n complete";

} 
what is the bug? i'm having a trouble with it!

Re: write data to a file wich received from GET

Posted: Wed Jun 02, 2010 4:57 pm
by Neo
fopen ( filename , 'a' ) will create a file if not exists. So first thing is you don't need to have the first part to create a file if it is not exists with 'w'. Just remove it and see whether it works.

To see how many bytes the fwrite has written, you may use echo fwrite(.......);

Re: write data to a file wich received from GET

Posted: Wed Jun 02, 2010 5:20 pm
by Rksk
Thakz neo.
it's working