You are here: Re: Editing Files: Help! « PHP Programming Language « IT news, forums, messages
Re: Editing Files: Help!

Posted by Jerry Stuckle on 07/31/07 01:23

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@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация