2 /* vim: set expandtab sw=4 ts=4 sts=4: */
5 * @package BLOBStreaming
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
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'];
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));
58 while (!feof($fHnd)) {
59 $content .= fread($fHnd, $f_size);
60 $pos = strlen($content);