• 06-05-2021, 18:20:53
    #1
    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.
  • 06-05-2021, 18:27:22
    #2
    Örnek kodlarınızı iletirseniz daha iyi yardımcı olabiliriz.
  • 06-05-2021, 18:39:26
    #3
    metehandemir adlı üyeden alıntı: mesajı görüntüle
    Örnek kodlarınızı iletirseniz daha iyi yardımcı olabiliriz.
    Merhaba
    $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.
  • 06-05-2021, 18:59:48
    #4
    Bu şekilde kullanabilirsiniz;
    $type = "file";
    $file = "giriskayitlari.txt";
    
    if(!empty($type) && $type == "file") {
      if(is_writable($file)) {
        $fc = file_get_contents($file);
        $fh = fopen($file, 'w');
        $content = "|---------------------\n";
        $content .= "| Time: ".$date->format('Y-m-d H:i:s')."\n";
        $content .= "| HTTP Referer: ".$href ."\n";
        $content .= "| Region: ".$regionName ."\n";
        $content .= "| City: ".$city ."\n";
        if(empty($fc)) {
          $content .= "|---------------------\n";
        }
        fwrite($fh, $content.$fc);
        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>");
      }
    }
  • 06-05-2021, 19:23:42
    #5
    metehandemir adlı üyeden alıntı: mesajı görüntüle
    Bu şekilde kullanabilirsiniz;
    $type = "file";
    $file = "giriskayitlari.txt";
    
    if(!empty($type) && $type == "file") {
      if(is_writable($file)) {
        $fc = file_get_contents($file);
        $fh = fopen($file, 'w');
        $content = "|---------------------\n";
        $content .= "| Time: ".$date->format('Y-m-d H:i:s')."\n";
        $content .= "| HTTP Referer: ".$href ."\n";
        $content .= "| Region: ".$regionName ."\n";
        $content .= "| City: ".$city ."\n";
        if(empty($fc)) {
          $content .= "|---------------------\n";
        }
        fwrite($fh, $content.$fc);
        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>");
      }
    }
    Eyvallah hocam çok teşekkürler.