1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
<?php
if(!isset($_GET['doc']))
exit('Please select a file... .. .');
function getMime($file)
{
$file = str_replace("\0",'',$file);
if(false === ($pos = strrpos($file,'.')))
return 'application/octet-stream';
$mimes = array(
'hqx' => 'application/mac-binhex40',
'doc' => 'application/msword',
'dot' => 'application/msword',
'bin' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => 'application/octet-stream',
'class' => 'application/octet-stream',
'so' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'pdf' => 'application/pdf',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'wbxml' => 'application/vnd.wap.wbxml',
'wmlc' => 'application/vnd.wap.wmlc',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'xla' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
'xlt' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'csh' => 'application/x-csh',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'spl' => 'application/x-futuresplash',
'gtar' => 'application/x-gtar',
'php' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'php5' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'js' => 'application/x-javascript',
'sh' => 'application/x-sh',
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xml',
'ent' => 'application/xml-external-parsed-entity',
'dtd' => 'application/xml-dtd',
'mod' => 'application/xml-dtd',
'gz' => 'application/x-gzip',
'zip' => 'application/zip',
'au' => 'audio/basic',
'snd' => 'audio/basic',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'kar' => 'audio/midi',
'mp1' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'm3u' => 'audio/x-mpegurl',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'wav' => 'audio/x-wav',
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'tiff' => 'image/tiff',
'tif' => 'image/tif',
'wbmp' => 'image/vnd.wap.wbmp',
'pnm' => 'image/x-portable-anymap',
'pbm' => 'image/x-portable-bitmap',
'pgm' => 'image/x-portable-graymap',
'ppm' => 'image/x-portable-pixmap',
'xbm' => 'image/x-xbitmap',
'xpm' => 'image/x-xpixmap',
'ics' => 'text/calendar',
'ifb' => 'text/calendar',
'css' => 'text/css',
'html' => 'text/html',
'htm' => 'text/html',
'asc' => 'text/plain',
'txt' => 'text/plain',
'rtf' => 'text/rtf',
'sgml' => 'text/x-sgml',
'sgm' => 'text/x-sgml',
'tsv' => 'text/tab-seperated-values',
'wml' => 'text/vnd.wap.wml',
'wmls' => 'text/vnd.wap.wmlscript',
'xsl' => 'text/xml',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo',
);
$ext = strtolower(substr($file,$pos+1));
return (isset($mimes[$ext]) ? $mimes[$ext] : 'application/octet-stream');
}
define('CFG_FILES_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'articles'.DIRECTORY_SEPARATOR);
$file = str_replace(array('../','..\\','./','.\\'),'',$_GET['doc']);
if(!is_file(CFG_FILES_PATH.$file))
exit('Requested file "'.$file.'" not found !!! .. .');
@error_reporting(0);
header('Pragma: public');
header('Last-Modified: '.gmdate("D, d M Y H:i:s").' GMT');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Date: '.gmdate("D, d M Y H:i:s", time()).' GMT');
header('Expires: '.gmdate("D, d M Y H:i:s", time()+1).' GMT');
header('Last-Modified: '.gmdate("D, d M Y H:i:s", time()).' GMT');
header('Content-Type: '.getMime($file).'; name="'.$file.'"');
echo file_get_contents(CFG_FILES_PATH.$file);
exit();
?> |
Partager