Warning: Undefined array key "search_mode" in /home/bakers/html/search.php on line 27

Warning: Undefined array key "include_body" in /home/bakers/html/search.php on line 28

Warning: Undefined array key 1328 in /home/bakers/html/search.php on line 247

Warning: Undefined array key 1335 in /home/bakers/html/search.php on line 247

Warning: Undefined variable $search_results in /home/bakers/html/search.php on line 257

Warning: Undefined variable $start in /home/bakers/html/search.php on line 261

Warning: Undefined variable $message in /home/bakers/html/search.php on line 63

Warning: Undefined variable $output in /home/bakers/html/search.php on line 65
Perturb.org - interesting technology related things from around the internet

Showing entries with tag "file".

Found 2 entries

Perl: Read a text file backwards by lines

I needed to read through a log file looking for certain entries backwards (newest entries first). Perl has a File::ReadBackwards module that does exactly this:

use File::ReadBackwards;

my $file = "/var/log/message";
my $fh   = File::ReadBackwards->new($file) or die "can't read $file";

while (defined(my $line = $fh->readline)) {
    print $line;
}
Leave A Reply

PHP: Serve file for download

If you want to a simple way to serve a file for download in PHP you can use this function:

function serve_file($filepath) {
    $filename = basename($filepath);

    if (headers_sent()) {
        die("Cannot output file because output already started");
    }

    $mime_type = mime_content_type($filepath);
    header("Content-type: $mime_type");
    header("Content-Disposition: attachment; filename=\"$filename\"");

    readfile($filepath);

    exit(0);
}
Leave A Reply