merhaba

fwrite ile txt dosyasına log tutturuyorum. bunları nası en yeni log en üste gelecek şekilde yazdırabilirim? şu anda en son gelen logu txt dosyasında en alta ekliyor.
$type = "file";
$file = "giriskayitlari.txt";

if(!empty($type) && $type == "file") {
  if(is_writable($file)) {
    $fh = fopen($file, 'a');
    if(filesize($file) < 32) {
      fwrite($fh, " LOG KAYITLARI ".$file."\n");
      fwrite($fh, "|---------------------\n");
    }
    fwrite($fh, '| Time: '.$date->format('Y-m-d H:i:s')."\n");
    fwrite($fh, '| HTTP Referer: '."".$href ."\n");
    fwrite($fh, '| Region: '."".$regionName ."\n");
    fwrite($fh, '| City: '."".$city ."\n");
    fwrite($fh, "|---------------------\n");
    fclose($fh);
  } else {
    chmod($file, 0777);
    die("<pre>Content could not load.\n");
    die("If you are the owner of this site, please adjust file permissions to allow writing to the file specified in config.</pre>");
  }
}
Bu şekilde düşünebiliriz işlemi.