Jump to content

Fwrite Write Twice


milukas

Recommended Posts

Helo everyone

 

My php code

 

<?php
if ($page == "Muzika")
{ $terms_failas = "./muzika_terms.txt";
}
elseif ($page=="Filmai")
{ $terms_failas = "./filmai_terms.txt";
}
elseif ($page=="Torentai")
{
$terms_failas = "./torentai_terms.txt";
}

if (isset($_GET['q'])) {
$terms = $_GET['q'];
$data = "$terms\n";
$fh = fopen($terms_failas,'a');
fwrite($fh, $data);
fclose($fh);
}

if ($page == "Muzika")
{ $f = "./muzika_terms.txt";
}
elseif ($page=="Filmai")
{ $f = "./filmai_terms.txt";
}
elseif ($page=="Torentai")
{
$f = "./torentai_terms.txt";
}
$size = filesize($f);
$fH = fopen($f,"r");
$data = fread($fH, $size);
fclose($fH);
?>

 

Its so simple but its write twice. i cant understand why.

 

 

 

 

this script i have wrote after, but I still getting double results...

<?php
$terms_failass = "terms.txt";
$data = "labuukas";
$fh = fopen($terms_failass,'a');
fwrite($fh, $data);
fclose($fh);
?>

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/270327-fwrite-write-twice/
Share on other sites

  • 4 weeks later...

well i don't see any logic in your code that would specifically write to the file twice, so that leaves 2 possibilities:

 

1) you are using fopen with the 'a' argument, which opens the file and puts the pointer to the end of the file.  Basically that means you are appending to the file. So, perhaps it's not really "double writing," but just writing once to a file that already had previous data from some previous test or w/e?

 

2) Somewhere else is calling your script twice.

 

 

Link to comment
https://forums.phpfreaks.com/topic/270327-fwrite-write-twice/#findComment-1395674
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.