From 5a2ea327d9766d5994cf394d4b0d867e480fd685 Mon Sep 17 00:00:00 2001 From: deseven Date: Sat, 12 Sep 2015 12:50:25 +0200 Subject: [PATCH] apply content-type based on file extension --- get.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/get.php b/get.php index 3ca5daa..dc96031 100644 --- a/get.php +++ b/get.php @@ -1,6 +1,20 @@ file($filename); + return $ctype; + } + } else { + function mime_content_type($filename) { + return "application/octet-stream"; + } + } +} + $file = ""; $id = intval($_GET['id']); if(empty($id)) exit; @@ -14,9 +28,14 @@ if (ob_get_level()) { ob_end_clean(); } + $defctype = "application/octet-stream"; + $ctype = mime_content_type($file); + if (!$ctype) { + $ctype = $defctype; + } header('Content-Description: File Transfer'); - header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename=' . $name); + header('Content-Type: ' . $ctype); + header('Content-Disposition: inline; filename=' . $name); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); @@ -24,4 +43,4 @@ header('Content-Length: ' . filesize($file)); readfile($file); exit; -} \ No newline at end of file +}