snippet library logo
Turnkey Websites from Built2go.com
in category
PHP / File Manipulation / Writing to the beginning of a file
Snippet details
ID: 234
Viewed: 2597
Added: 2002-06-10
Version:
Sorry no demo

User Rated at: 3 Stars
Rate This:
Snippets in this catagory         
Show Printable Version
Very handy to have around. you have a text file that is huge and want to append to it. but you don't want the new data to go clear to the bottom of the file. Well this script will let you do just the opposite. It will let you write to the file but put the new data at the begining and the old data at the end.

General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: unknown

<!---Head--->
none

<!---Body--->


<?
$file_name 
"nieuws.txt"

#open and place the $fp point at the beginning of the file 
$fp=fopen("$file_name""r+");

#prevent the file from being messed up. 
flock($fp2);

#read in the old data 
$old_data fread($fpfilesize($file_name));

# reset the file pointer to the start of the file so that the fwrite overwrites the original data 
rewind($fp);

#concat the new data then the old data 
fwrite($fp"new data" $old_data); 

#release the lock, fclose can also do this 
flock($fp,3);

#close the file 
fclose($fp);
?>




No Reviews to show


Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.