Ignore:
Timestamp:
04/14/15 17:00:49 (10 years ago)
Author:
smueller
Message:
log file is now opened, seeked close to the end and then read. This enables large log files to still be printed to showlog.php webpage.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/www/showlog/index.php

    r17928 r18168  
    335335
    336336$size = filesize($filename);
    337 if ($size>30000000) // 30MB
    338 {
    339     header('HTTP/1.1 403 File too large.');
    340     print("File too large.\n");
    341     return;
    342 }
    343 
    344 // FIXME: Reading the file line by line avoids any danger that
    345 //        something yields a problem if files grow too large
    346 $file = file($filename);
    347 if ($file===false)
     337
     338$file=array();
     339$fp = fopen($filename, "r");
     340
     341if ($fp===false)
    348342{
    349343    header('HTTP/1.1 403 Access forbidden.');
     
    352346}
    353347
    354 $max = 10000;
    355 $pos = 500;
    356 $n = count($file);
    357 if ($n>$max)
    358 {
    359     $file[$pos] = "\n<b>[...]</b>\n\n";
    360     array_splice($file, $pos+1, $n-$max);
    361 }
     348fseek($fp, -min(10000000, $size), SEEK_END);
     349fgets($fp);
     350while(!feof($fp))
     351{
     352   $line = fgets($fp);
     353   array_push($file, $line);
     354}
     355fclose($fp);
     356
    362357
    363358$dir  = basename(dirname($filename));
Note: See TracChangeset for help on using the changeset viewer.