Append Code to the beginning of a large file

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
aderes
Forum Newbie
Posts: 6
Joined: Wed May 06, 2009 6:34 pm

Append Code to the beginning of a large file

Post by aderes »

Hi Everyone:

I'm having a little trouble trying to append to the top of a file in PHP. I've seen examples where the content is copied, but I'm worried that if the file content gets too big I might run into memory issues.

I've tried rewinding and moving the cursor, but it always appends to the bottom.

Any help would be greatly appreciated.

Thanks
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Append Code to the beginning of a large file

Post by crazycoders »

You can do it using apache or SSI includes... No need to use php to read the file...

Search for APACHE server side includes using HTACCESS
Or you could use SSI includes using a small tag you place at the top of your files!

Finaly, remember that you can buffer out a file all at once without taking memory using readfile()... At least i think thats the function, i never used it. One of the many php file functions can read a file to the output buffer, so i guess that could be one of your best choices.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Append Code to the beginning of a large file

Post by John Cartwright »

Take a look at the different modes in fopen()
Post Reply