From 4129e1893830ebfa2cf8f76532f687080ebc7970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 25 Jan 2010 11:51:15 +0000 Subject: [PATCH] Add MIME type detection to download (at least for images). RFE#2937494 --- libraries/mime.lib.php | 27 +++++++++++++++++++++++++++ tbl_get_field.php | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 libraries/mime.lib.php diff --git a/libraries/mime.lib.php b/libraries/mime.lib.php new file mode 100644 index 000000000..6ee5249a9 --- /dev/null +++ b/libraries/mime.lib.php @@ -0,0 +1,27 @@ += 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) { + return 'image/jpeg'; + } + if ($len >= 3 && substr($test, 0, 3) == 'GIF') { + return 'image/gif'; + } + if ($len >= 4 && substr($test, 0, 4) == "\x89PNG") { + return 'image/png'; + } + return 'application/octet-stream'; +} +?> diff --git a/tbl_get_field.php b/tbl_get_field.php index d03da2aab..34d88828a 100644 --- a/tbl_get_field.php +++ b/tbl_get_field.php @@ -10,6 +10,7 @@ * Common functions. */ require_once './libraries/common.inc.php'; +require_once './libraries/mime.lib.php'; /* Check parameters */ PMA_checkParameters(array('db', 'table', 'where_clause', 'transform_key')); @@ -37,7 +38,7 @@ if ($result === false) { /* Avoid corrupting data */ @ini_set('url_rewriter.tags',''); -header('Content-Type: application/octet-stream'); +header('Content-Type: ' . PMA_detectMIME($result)); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="' . $table . '-' . $transform_key . '.bin"'); if (PMA_USR_BROWSER_AGENT == 'IE') {