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
Append Code to the beginning of a large file
Moderator: General Moderators
-
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
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.
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.
- 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
Take a look at the different modes in fopen()