milukas Posted November 5, 2012 Share Posted November 5, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270327-fwrite-write-twice/ Share on other sites More sharing options...
.josh Posted November 27, 2012 Share Posted November 27, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270327-fwrite-write-twice/#findComment-1395674 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.