Page 1 of 1

Anyone have any append to top of flat file code?

Posted: Fri May 18, 2007 1:47 am
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

Posted: Fri May 18, 2007 1:58 am
by John Cartwright
Your going to have to rewrite the file if you want to prepend data, unfortunantly.

Posted: Tue May 22, 2007 3:01 am
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!

Posted: Tue May 22, 2007 3:17 am
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.