Translation update done using Pootle.
[phpmyadmin-themes.git] / bs_disp_as_mime_type.php
bloba83dfa66eea633f95b0860333d04970baa90fcc3
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @version 1.0
5 * @package BLOBStreaming
6 */
8 /**
9 * Core library.
11 require_once './libraries/common.inc.php';
13 // load PMA configuration
14 $PMA_Config = $GLOBALS['PMA_Config'];
16 // retrieve BS server variables from PMA configuration
17 $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER');
18 if (empty($bs_server)) die('No blob streaming server configured!');
20 // Check URL parameters
21 PMA_checkParameters(array('reference', 'c_type'));
23 // Increase time limit, because fetching blob might take some time
24 set_time_limit(0);
26 $reference = $_REQUEST['reference'];
28 * FIXME: Maybe it would be better to check MIME type against whitelist as
29 * this code sems to support only few MIME types (check
30 * function PMA_BS_CreateReferenceLink in libraries/blobstreaming.lib.php).
32 $c_type = preg_replace('/[^A-Za-z0-9/_-]/', '_', $_REQUEST['c_type']);
34 $filename = 'http://' . $bs_server . '/' . $reference;
36 $hdrs = get_headers($filename, 1);
38 if ($hdrs === FALSE) die('Failed to fetch headers');
40 $fHnd = fopen($filename, "rb");
42 if ($fHnd === FALSE) die('Failed to open remote URL');
44 $f_size = $hdrs['Content-Length'];
46 header("Expires: 0");
47 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
48 header("Cache-Control: no-store, no-cache, must-revalidate");
49 header("Cache-Control: post-check=0, pre-check=0", false);
50 header("Pragma: no-cache");
51 header("Content-type: $c_type");
52 header('Content-length: ' . $f_size);
53 header("Content-disposition: attachment; filename=" . basename($filename));
55 $pos = 0;
56 $content = "";
58 while (!feof($fHnd)) {
59 $content .= fread($fHnd, $f_size);
60 $pos = strlen($content);
62 if ($pos >= $f_size)
63 break;
66 echo $content;
67 flush();
69 fclose($fHnd);