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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.