Anyone have any append to top of flat file code?

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
AppleBag
Forum Newbie
Posts: 2
Joined: Fri May 18, 2007 1:42 am

Anyone have any append to top of flat file code?

Post by AppleBag »

Hello all

I am learning the ropes in PHP at the moment, and I have the append-to-bottom using fopen, working fine. however, I would like to also be able to append to the top without overwriting any old data in the file. So it works like a stack, whatever was there at the top originally gets pushed down a notch and the new data goes on top. I have tried using r+, but obviously that only places the cursor at the top.

Any help would be greatly appreciated. :D
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Your going to have to rewrite the file if you want to prepend data, unfortunantly.
AppleBag
Forum Newbie
Posts: 2
Joined: Fri May 18, 2007 1:42 am

Post by AppleBag »

Ahh dang. I was afraid of that. Being new to php (I do classic vb, and learning vb.net), can you point me to the functions to do this, or maybe some easy sample code?

thanks!
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

sounds like you want to get the contents of the file, append them to an existing var, then put the contents back in the file.
Post Reply