1<?php
2
3if (isset($_GET['file'])){
4	$filename =$_GET['file'];
5	$archivRootDir = $_GET[ 'something'];
6
7	$downloadFile = $archivRootDir . '/' . $filename;
8
9	header ( "Content-Type: ". get_mime_type($filename) );
10	header ( "Content-Disposition: attachment; filename=" . $filename );
11	header ( "Content-Length: " . filesize ( $downloadFile ) );
12	readfile ( $downloadFile );
13	return;
14}
15
16
17function get_mime_type($filename) {
18	$idx = explode( '.', $filename );
19	$count_explode = count($idx);
20	$idx = strtolower($idx[$count_explode-1]);
21
22	$mimet = array(
23			'txt' => 'text/plain',
24			'htm' => 'text/html',
25			'html' => 'text/html',
26			'php' => 'text/html',
27			'css' => 'text/css',
28			'js' => 'application/javascript',
29			'json' => 'application/json',
30			'xml' => 'application/xml',
31			'swf' => 'application/x-shockwave-flash',
32			'flv' => 'video/x-flv',
33
34			// images
35			'png' => 'image/png',
36			'jpe' => 'image/jpeg',
37			'jpeg' => 'image/jpeg',
38			'jpg' => 'image/jpeg',
39			'gif' => 'image/gif',
40			'bmp' => 'image/bmp',
41			'ico' => 'image/vnd.microsoft.icon',
42			'tiff' => 'image/tiff',
43			'tif' => 'image/tiff',
44			'svg' => 'image/svg+xml',
45			'svgz' => 'image/svg+xml',
46
47			// archives
48			'zip' => 'application/zip',
49			'rar' => 'application/x-rar-compressed',
50			'exe' => 'application/x-msdownload',
51			'msi' => 'application/x-msdownload',
52			'cab' => 'application/vnd.ms-cab-compressed',
53
54			// audio/video
55			'mp3' => 'audio/mpeg',
56			'qt' => 'video/quicktime',
57			'mov' => 'video/quicktime',
58
59			// adobe
60			'pdf' => 'application/pdf',
61			'psd' => 'image/vnd.adobe.photoshop',
62			'ai' => 'application/postscript',
63			'eps' => 'application/postscript',
64			'ps' => 'application/postscript',
65
66			// ms office
67			'doc' => 'application/msword',
68			'rtf' => 'application/rtf',
69			'xls' => 'application/vnd.ms-excel',
70			'ppt' => 'application/vnd.ms-powerpoint',
71
72
73			// open office
74			'odt' => 'application/vnd.oasis.opendocument.text',
75			'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
76
77			// START MS Office 2007 Docs
78			'docx'
79			=> 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
80			'docm'
81			=> 'application/vnd.ms-word.document.macroEnabled.12',
82			'dotx'
83			=> 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
84			'dotm'
85			=> 'application/vnd.ms-word.template.macroEnabled.12',
86			'xlsx'
87			=> 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
88			'xlsm'
89			=> 'application/vnd.ms-excel.sheet.macroEnabled.12',
90			'xltx'
91			=> 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
92			'xltm'
93			=> 'application/vnd.ms-excel.template.macroEnabled.12',
94			'xlsb'
95			=> 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
96			'xlam'
97			=> 'application/vnd.ms-excel.addin.macroEnabled.12',
98			'pptx'
99			=> 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
100			'pptm'
101			=> 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
102			'ppsx'
103			=> 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
104			'ppsm'
105			=> 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
106			'potx'
107			=> 'application/vnd.openxmlformats-officedocument.presentationml.template',
108			'potm'
109			=> 'application/vnd.ms-powerpoint.template.macroEnabled.12',
110			'ppam'
111			=> 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
112			'sldx'
113			=> 'application/vnd.openxmlformats-officedocument.presentationml.slide',
114			'sldm'
115			=> 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
116			'one'
117			=> 'application/msonenote',
118			'onetoc2'
119			=> 'application/msonenote',
120			'onetmp'
121			=> 'application/msonenote',
122			'onepkg'
123			=> 'application/msonenote',
124			'thmx'
125			=> 'application/vnd.ms-officetheme'
126	);
127
128	if (isset( $mimet[$idx] )) {
129		return $mimet[$idx];
130	} else {
131		return 'application/octet-stream';
132	}
133
134}