Hi, Philipp,
Weiß einer von euch, wie man in PHP Daten an den Anfang und nicht an das Ende einer Datei hängt?
Dazu habe ich ein Beispiel gefunden: Bei starker Serverbelastung solltest Du allerdings überprüfen, wie sich diese Methode auf die Performance auswirkt ...
Insert To Top Of File
This small snippet will work around php's innability to insert data when you open a file with the pointer at the begining, php simply over writes it.
<?php
$data = file("/data.txt"); // file you want insert line into
$c = count($data); // count existing lines
$fp = fopen("/data.txt", 'w+'); // open the file for writing
fwrite($fp, $entry); // this is where it would add your 'entry'
for($i=0; $i<$c;$i++){ // write back the old data
fwrite($fp, $data);
}
fclose($fp); // close up the file
?>
Quelle:
[http://www.evilwalrus.com/viewcode.php?codeEx=219]
Grüße,
Sebastian