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
newmember
Forum Contributor
Posts: 252 Joined: Fri Apr 02, 2004 12:36 pm
Post
by newmember » Sat Sep 18, 2004 6:16 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 18, 2004 6:23 pm
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...
newmember
Forum Contributor
Posts: 252 Joined: Fri Apr 02, 2004 12:36 pm
Post
by newmember » Sat Sep 18, 2004 6:40 pm
docs say nothing about return value in this case...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 18, 2004 7:50 pm
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 » Mon Sep 20, 2004 6:13 am
why don't u use fopen ($file, "a+b"); ?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Sep 20, 2004 7:08 am
thanks for repeating what I said 2 days ago.
newmember
Forum Contributor
Posts: 252 Joined: Fri Apr 02, 2004 12:36 pm
Post
by newmember » Tue Sep 21, 2004 3:18 am
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