<?php
// ###############################################
// Filename: getFile.php
// Author: Albert Holtsclaw, www.albybum.net
// Email: albybum@albybum.net
// ###############################################
// Installation and use:
// Copy this script to a text file with the .php extension
// getFile.php for example.
//
// Modify the example case section to fit your file information.
// A new case will need to be created for each file.
//
// Link to the script with the id of the file you want to download.
// getFile.php?id=Some_ID
// http://www.albybum.net/download/getFile.php?id=wow1.4
// ###############################################
// Functions
function showError($error)
{
print "There has been an error. <br />";
print "Error Code: ".$error;
return true;
}
// ERROR Lists
// 2021 bandwidth exceeded
// 404 not found
// Set Defaults
$error="404";
$allow=false;
// Retrieve the file id from input
$id=$_GET['id'];
// Switch, Case block
switch ($id)
{
// :: EXAMPLE CASE
// ########### THE_ART_OF_SHADOWBLADERY ###########
case "201":
// File Mime Type
$type = 'video/x-ms-wmv';
// File Name
$filename = 'THE_ART_OF_SHADOWBLADERY.wmv';
// Path to file, relative to this script
$path = 'store/THE_ART_OF_SHADOWBLADERY.wmv';
// Whether to allow this download, set false to stop download
$allow=true;
break;
// :: TODO - modify this case to fit your file information
// :: EMPTY CASE
// ########### SOME FILENAME COMMENT ###########
case "SOME_UNIQUE_ID":
$type = 'application/zip';
$filename = 'SOME_FILE.zip';
$path = 'downloads/store/SOME_FILE.zip';
$allow=true;
break;
// :: Default case if nothing matches the ID
// ########### DEFAULT ###########
default:
$error="404";
break;
}
// IF Allow has been set through a file case, allow download.
if ($allow==true)
{
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=$filename");
readfile($path);
}
else
{
showError($error);
}
?>