<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Moja strona WWW</title>
</head>
<body>
<div>
<?php
function send($id)
{
  if(!($fd = fopen("downloads.txt","r"))){
    return false;
  }

  $found = false;

  while (!feof ($fd)){
    $line = trim(fgets($fd));
    $arr = explode(";", $line);
    if(count($arr) == 4){
      if($id === $arr[0]){
        $found = true;
        $path = $arr[2];
        $name = $arr[1];
        break;
      }
    }
  }

  if((!$found) || (!file_exists($path.$name))){
    return false;
  }

  if(!($fd = fopen($path.$name, "r"))){
    return false;
  }
  $size = filesize($path.$name);
  $contents = fread($fd, $size);

  fclose($fd);

  header("Content-Type: application/octet-stream");
  header("Content-Length: $size;");
  header("Content-Disposition: attachment; filename=$name");

  echo $contents;
  return true;
}

if(isSet($_GET['fileid'])){
  if(!send($_GET['fileid'])){
    include "nofile.html";
  }
}
else{
  include "download_list.php";
}
?>
</div>
</body>
</html>