File : download.php

<?php
/**
 * Download script
 *
 * By S.E.
 */

//Path prevent
require_once("fonc.php");

//Type table (ext => type)
$Ext2Type['iges'] = "application/iges";
$Ext2Type['js'] = "application/javascript";
$Ext2Type['dxf'] = "application/dxf";
$Ext2Type['mp4'] = "application/mp4";
$Ext2Type['igs'] = "application/iges";
$Ext2Type['iges'] = "application/iges";
$Ext2Type['bin'] = "application/octet-stream";
$Ext2Type['doc'] = "application/msword";
$Ext2Type['pdf'] = "application/pdf";
$Ext2Type['ai'] = "application/postscript";
$Ext2Type['eps'] = "application/postscript";
$Ext2Type['ps'] = "application/postscript";
$Ext2Type['rtf'] = "application/rtf";
$Ext2Type['sgml'] = "application/sgml";
$Ext2Type['xls'] = "ms-excel";
$Ext2Type['ppt'] = "ms-powerpoint";
$Ext2Type['xml'] = "application/xml";
$Ext2Type['tar'] = "application/x-tar";
$Ext2Type['zip'] = "application/zip";
$Ext2Type['au'] = "audio/basic";
$Ext2Type['snd'] = "audio/basic";
$Ext2Type['mpg'] = "audio/mpeg";
$Ext2Type['mp3'] = "audio/mpeg";
$Ext2Type['mp4'] = "audio/mp4";
$Ext2Type['aif'] = "audio/x-aiff";
$Ext2Type['aiff'] = "audio/x-aiff";
$Ext2Type['aifc'] = "audio/x-aiff";
$Ext2Type['wav'] = "audio/x-wav";
$Ext2Type['gif'] = "image/gif";
$Ext2Type['jpg'] = "image/jpeg";
$Ext2Type['jpeg'] = "image/jpeg";
$Ext2Type['jpe'] = "image/jpeg";
$Ext2Type['png'] = "image/png";
$Ext2Type['tiff'] = "image/tiff";
$Ext2Type['tif'] = "image/tiff";
$Ext2Type['pbm'] = "image/x-portable-bitmap";
$Ext2Type['pgm'] = "image/x-portable-graymap";
$Ext2Type['ppm'] = "image/x-portable-pixmap";
$Ext2Type['zip'] = "multipart/x-zip";
$Ext2Type['gz'] = "multipart/x-gzip";
$Ext2Type['gzip'] = "multipart/x-gzip";
$Ext2Type['css'] = "text/css";
$Ext2Type['csv'] = "text/csv";
$Ext2Type['htm'] = "text/html";
$Ext2Type['html'] = "text/html";
$Ext2Type['txt'] = "text/plain";
$Ext2Type['g'] = "text/plain";
$Ext2Type['h'] = "text/plain";
$Ext2Type['c'] = "text/plain";
$Ext2Type['cc'] = "text/plain";
$Ext2Type['hh'] = "text/plain";
$Ext2Type['m'] = "text/plain";
$Ext2Type['f90'] = "text/plain";
$Ext2Type['rtx'] = "text/richtext";
$Ext2Type['rtf'] = "text/rtf";
$Ext2Type['tsv'] = "text/tab-separated-value";
$Ext2Type['xml'] = "text/xml";
$Ext2Type['h264'] = "video/h264";
$Ext2Type['dv'] = "video/dv";
$Ext2Type['mpeg'] = "video/mpeg";
$Ext2Type['mpg'] = "video/mpeg";
$Ext2Type['mpe'] = "video/mpeg";
$Ext2Type['qt'] = "video/quicktime";
$Ext2Type['mov'] = "video/quicktime";
$Ext2Type['avi'] = "video/msvideo";

//Download path
$path "";

//Get the download path
if(isset($_GET['path']))
    
$path $_GET['path'];
if(isset(
$_POST['path']))
    
$path $_POST['path'];

//Protect path
$path path_prevent($path"file");

//If we can find this file
if($path && file_exists($path))
{
    
//Get file name
    
$filename basename($path);

    
//Default type
    
$type "application/octet-stream";
    
//Select type from ext
    
$ext str_replace("."nullstrrchr($filename"."));

    if(isset(
$Ext2Type[$ext]))
        
$type $Ext2Type[$ext];

    
//Force download
    
header("Content-disposition: attachment; filename=".$filename);
    
header("Content-Type: application/force-download");
    
header("Content-Transfer-Encoding: $type\n");
    
header("Content-Length: ".filesize($path));
    
header("Pragma: no-cache");
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0, public");
    
header("Expires: 0");

    
//Load data
    
readfile($path);
}
//We can't :/
else
    
header("Location: /40X/404.php");
?>


Valid XHTML 1.1