Add MIME type detection to download (at least for images).
RFE#2937494
This commit is contained in:
27
libraries/mime.lib.php
Normal file
27
libraries/mime.lib.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||||
|
/**
|
||||||
|
* MIME detection code.
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
* @package phpMyAdmin
|
||||||
|
* @todo Maybe we could try to use fileinfo module if loaded
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to detect MIME type of content.
|
||||||
|
*/
|
||||||
|
function PMA_detectMIME(&$test) {
|
||||||
|
$len = strlen($test);
|
||||||
|
if ($len >= 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';
|
||||||
|
}
|
||||||
|
?>
|
@@ -10,6 +10,7 @@
|
|||||||
* Common functions.
|
* Common functions.
|
||||||
*/
|
*/
|
||||||
require_once './libraries/common.inc.php';
|
require_once './libraries/common.inc.php';
|
||||||
|
require_once './libraries/mime.lib.php';
|
||||||
|
|
||||||
/* Check parameters */
|
/* Check parameters */
|
||||||
PMA_checkParameters(array('db', 'table', 'where_clause', 'transform_key'));
|
PMA_checkParameters(array('db', 'table', 'where_clause', 'transform_key'));
|
||||||
@@ -37,7 +38,7 @@ if ($result === false) {
|
|||||||
/* Avoid corrupting data */
|
/* Avoid corrupting data */
|
||||||
@ini_set('url_rewriter.tags','');
|
@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('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||||
header('Content-Disposition: attachment; filename="' . $table . '-' . $transform_key . '.bin"');
|
header('Content-Disposition: attachment; filename="' . $table . '-' . $transform_key . '.bin"');
|
||||||
if (PMA_USR_BROWSER_AGENT == 'IE') {
|
if (PMA_USR_BROWSER_AGENT == 'IE') {
|
||||||
|
Reference in New Issue
Block a user