2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * @package BLOBStreaming
10 require_once './libraries/common.inc.php';
12 // Check URL parameters
13 PMA_checkParameters(array('reference', 'c_type'));
15 // Increase time limit, because fetching blob might take some time
18 $reference = $_REQUEST['reference'];
20 * FIXME: Maybe it would be better to check MIME type against whitelist as
21 * this code sems to support only few MIME types (check
22 * function PMA_BS_CreateReferenceLink in libraries/blobstreaming.lib.php).
24 $c_type = preg_replace('/[^A-Za-z0-9/_-]/', '_', $_REQUEST['c_type']);
26 // Get the blob streaming URL
27 $filename = PMA_BS_getURL($reference);
28 if (empty($filename)) {
29 die(__('No blob streaming server configured!'));
32 $hdrs = get_headers($filename, 1);
34 if ($hdrs === false) {
35 die(__('Failed to fetch headers'));
38 $fHnd = fopen($filename, "rb");
40 if ($fHnd === false) {
41 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);
62 if ($pos >= $f_size) {