this snippet let's you insert data at the beginning of a file. it reads
the contents and adds new data to the first line of the file. after this
it joins the lines and writes them back to the file again.
01<?php 02 03// your new data + newline 04$new_line='some new data here'."\n"; 05 06// the filepath 07$file='temp/file.txt'; 08 09// the old data as array 10$old_lines=file($file); 11 12// add new line to beginning of array 13array_unshift($old_lines,$new_line); 14 15// make string out of array 16$new_content=join('',$old_lines); 17$fp=fopen($file,'w'); 18 19// write string to file 20$write=fwrite($fp,$new_content); 21fclose($fp); 22 23?>