Re: Editing Files: Help!
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Mon, 30 Jul 2007 21:23:03 -0400
ttrium wrote:
Ok, so this is probably the easist question ever posted, but I
honestly can't find the answer (if there is one).
How do I (by which function) add data to a file at the beginning of a
file, rather than the end of the file (as is with fopen(file, "a"))?
Two ways:
1. Open the file, read it all into memory, truncate the file, write the new data followed by the old data.
2. Open the file, open a temporary file, write the new data to the temporary file, copy the data from the original file to the temporary file, close both files. delete the original file and rename the temporary file.
#2 is obviously more work, but it doesn't require lots of memory to read a large file into memory, and won't lose the file if the system crashes in the middle.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- References:
- Editing Files: Help!
- From: ttrium
- Editing Files: Help!
- Prev by Date: Re: Editing Files: Help!
- Next by Date: passing $_POST variables to classes
- Previous by thread: Re: Editing Files: Help!
- Next by thread: passing $_POST variables to classes
- Index(es):
Relevant Pages
|