'application/javascript', 'rss' => 'application/rss+xml', 'xhtml' => 'application/xhtml+xml', 'xml' => 'application/xml', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'ico' => 'image/x-icon', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'txt' => 'text/plain'); // Remove ../ es $file = str_replace('../', '', $file); if (!file_exists($file)) { echo file_get_contents('404.html'); // 404 exit(); } $type = filetype($file); if (!$type) { echo file_get_contents('404.html'); // 404 exit(); } else if ($type == 'dir') { $file .= 'index.html'; if (file_exists($file)) { echo file_get_contents($file); } else { echo file_get_contents('404.html'); // 404 exit(); } } else if ($type == 'file') { if (file_exists($file)) { $dot_pos = strrchr($file, '.'); if ($dot_pos !== false) { $ext = substr($dot_pos, 1); if (in_array($ext, $extension_type)) { header ("Content-Type: ".$extension_mime[$ext]); header ("Last-Modified: " . gmdate("D, d M Y H:i:s",filemtime($file)) . " GMT"); header ("Expires: Mon, 26 Jul 2040 05:00:00 GMT"); // In other words... never expire the image header ("Cache-Control: max-age=10000000, s-maxage=1000000, proxy-revalidate, must-revalidate"); echo file_get_contents($file); } else { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); echo file_get_contents($file); } } else { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); echo file_get_contents($file); } } else { echo file_get_contents('404.html'); // 404 exit(); } } else { echo file_get_contents('404.html'); // 404 exit(); } ?>