2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * @author Raj Kissu Rajandran
6 * @package BLOBStreaming
12 require_once './libraries/common.inc.php';
14 // load PMA configuration
15 $PMA_Config = $GLOBALS['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
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'];
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));
59 while (!feof($fHnd)) {
60 $content .= fread($fHnd, $f_size);
61 $pos = strlen($content);