Page 1 of 1

problem with ftell()

Posted: Sat Sep 18, 2004 6:16 pm
by newmember
i'm using php 4.3.5 on windows xp(+ local apache)

these lines are excuted each time user submits form:
(i want to append data)

Code: Select all

...
$fh=fopen("data.dat","r+b"); //open file for read/write
fseek($fh,0,SEEK_END); //move pointer to end of file for append
$pos=ftell($fh);
if($pos===false)
    echo("ftell failed");
....
i don't understand why but ftell() failes 8O

Posted: Sat Sep 18, 2004 6:23 pm
by feyd
ftell fails when it's at EOF or later. seeking to zero bytes from the end, is EOF. ... at least that's how it worked in C from what I remember...

Posted: Sat Sep 18, 2004 6:40 pm
by newmember
docs say nothing about return value in this case...

Posted: Sat Sep 18, 2004 7:50 pm
by feyd
why not use the append mode when opening the file? or a database (safer)

Posted: Mon Sep 20, 2004 6:13 am
by PerfectPC
why don't u use fopen ($file, "a+b"); ?

Posted: Mon Sep 20, 2004 7:08 am
by feyd
thanks for repeating what I said 2 days ago. :roll:

Posted: Tue Sep 21, 2004 3:18 am
by newmember
ok thanks
i got it to work right now
the problem was that i didn't actualy create the file... fopen("","r") doesn't create file