problem with ftell()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

problem with ftell()

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post by newmember »

docs say nothing about return value in this case...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why not use the append mode when opening the file? or a database (safer)
PerfectPC
Forum Newbie
Posts: 1
Joined: Mon Sep 20, 2004 6:12 am

Post by PerfectPC »

why don't u use fopen ($file, "a+b"); ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

thanks for repeating what I said 2 days ago. :roll:
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

Post 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
Post Reply