<?php
$filename = 'c_leitura.php';
session_start();

if (!file_exists($filename)) {
  header("Location: error.php"); exit;   
}				
include 'c_leitura.php';

require_once("db.php");

$id = $_GET['id'];

$query = "SELECT text FROM crashlog WHERE id='$id'";
$result = mysql_query ($query) or die(mysql_error());
$row = mysql_fetch_array($result);

header ("Content-Type: application/octet-stream");
header ("Content-disposition: attachment; filename=crashlog-" . $id . ".txt");

echo $row['text'];
?>