<?php
// brandon long
// brandon@x10hosting.com
// example: ?id=filename
// get the query string
if (!$_GET['id'])
// die off, could be an error page tooo
die("Need to specifiy a file.");
// set the diretory to were the files are located
$dirOfFiles = ''; // for this example, we will say it's /home/brandon/downloads
// Set the below variable to the ext.
$fileEndExt = '.exe';
// below it will set the full path
$pathToFile = $dirOfFiles . $_GET['id'] . $fileEndExt;
// lets open the file
if ($fileOpenType = fopen($pathToFile, 'r')) {
//get the file size
$fileSizeInfo = filesize($pathToFile);
// setup some variables to exit
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"". $_GET['id'] . $fileEndExt ."\"");
header("Content-length: $fileSizeInfo");
// this outputs the file via the script
while(!feof($fileOpenType)) {
echo fread($fd, 2048);
}
fclose($fileOpenType);
} else {
// file ain't there yo, die off
die('No file named ' . $_GET['id'] . $fileEndExt . ' exists on the server.');
}
?>