there was an extra space in the ChangeLog
[phpmyadmin/crack.git] / bs_disp_as_mime_type.php
blob4a9bdc155e3492338ad71f195d87c1dddca55978
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @author Raj Kissu Rajandran
5 * @version 1.0
6 * @package BLOBStreaming
7 */
9 /**
10 * Core library.
12 require_once './libraries/common.inc.php';
14 // load PMA configuration
15 $PMA_Config = $_SESSION['PMA_Config'];
17 // retrieve BS server variables from PMA configuration
18 $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER');
19 if (empty($bs_server)) die('No blob streaming server configured!');
21 // Check URL parameters
22 PMA_checkParameters(array('reference', 'c_type'));
24 // Increase time limit, because fetching blob might take some time
25 set_time_limit(0);
27 $reference = $_REQUEST['reference'];
29 * FIXME: Maybe it would be better to check MIME type against whitelist as
30 * this code sems to support only few MIME types (check
31 * function PMA_BS_CreateReferenceLink in libraries/blobstreaming.lib.php).
33 $c_type = preg_replace('/[^A-Za-z0-9/_-]/', '_', $_REQUEST['c_type']);
35 $filename = 'http://' . $bs_server . '/' . $reference;
37 $hdrs = get_headers($filename, 1);
39 if ($hdrs === FALSE) die('Failed to fetch headers');
41 $fHnd = fopen($filename, "rb");
43 if ($fHnd === FALSE) die('Failed to open remote URL');
45 $f_size = $hdrs['Content-Length'];
47 header("Expires: 0");
48 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
49 header("Cache-Control: no-store, no-cache, must-revalidate");
50 header("Cache-Control: post-check=0, pre-check=0", false);
51 header("Pragma: no-cache");
52 header("Content-type: $c_type");
53 header('Content-length: ' . $f_size);
54 header("Content-disposition: attachment; filename=" . basename($filename));
56 $pos = 0;
57 $content = "";
59 while (!feof($fHnd)) {
60 $content .= fread($fHnd, $f_size);
61 $pos = strlen($content);
63 if ($pos >= $f_size)
64 break;
67 echo $content;
68 flush();
70 fclose($fHnd);