* Core library.
 */
require_once './libraries/common.inc.php';
// Check URL parameters
PMA_checkParameters(array('reference', 'c_type'));
// Increase time limit, because fetching blob might take some time
set_time_limit(0);
$reference = $_REQUEST['reference'];
/*
 * FIXME: Maybe it would be better to check MIME type against whitelist as
 * this code sems to support only few MIME types (check
 * function PMA_BS_CreateReferenceLink in libraries/blobstreaming.lib.php).
 */
$c_type = preg_replace('/[^A-Za-z0-9/_-]/', '_', $_REQUEST['c_type']);
// Get the blob streaming URL
$filename = PMA_BS_getURL($reference);
if (empty($filename)) {
    die(__('No blob streaming server configured!'));
}
$hdrs = get_headers($filename, 1);
if ($hdrs === FALSE) {
    die(__('Failed to fetch headers'));
}
$fHnd = fopen($filename, "rb");
if ($fHnd === FALSE) {
    die(__('Failed to open remote URL'));
}
$f_size = $hdrs['Content-Length'];
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
Esempio n. 2
0
function PMA_BS_CreateReferenceLink($bs_reference, $db_name)
{
    if (PMA_do_connect($db_name, false) == false) {
        return __('Error');
    }
    if (pbms_get_info(trim($bs_reference)) == false) {
        PMA_BS_ReportPBMSError(__('PBMS get BLOB info failed:') . " pbms_get_info({$bs_reference})");
        PMA_do_disconnect();
        return __('Error');
    }
    $content_type = pbms_get_metadata_value("Content-Type");
    if ($content_type == false) {
        $br = trim($bs_reference);
        PMA_BS_ReportPBMSError("PMA_BS_CreateReferenceLink('{$br}', '{$db_name}'): " . __('PBMS get BLOB Content-Type failed'));
    }
    PMA_do_disconnect();
    if (!$content_type) {
        $content_type = "image/jpeg";
    }
    $bs_url = PMA_BS_getURL($bs_reference);
    if (empty($bs_url)) {
        PMA_BS_ReportPBMSError(__('No blob streaming server configured!'));
        return 'Error';
    }
    $output = $content_type;
    // specify custom HTML for various content types
    switch ($content_type) {
        // no content specified
        case null:
            $output = "NULL";
            break;
            // image content
        // image content
        case 'image/jpeg':
        case 'image/png':
            $output .= ' (<a href="' . $bs_url . '" target="new">' . __('View image') . '</a>)';
            break;
            // audio content
        // audio content
        case 'audio/mpeg':
            $output .= ' (<a href="#" onclick="popupBSMedia(\'' . PMA_generate_common_url() . '\',\'' . urlencode($bs_reference) . '\', \'' . urlencode($content_type) . '\',' . ($is_custom_type ? 1 : 0) . ', 640, 120)">' . __('Play audio') . '</a>)';
            break;
            // video content
        // video content
        case 'application/x-flash-video':
        case 'video/mpeg':
            $output .= ' (<a href="#" onclick="popupBSMedia(\'' . PMA_generate_common_url() . '\',\'' . urlencode($bs_reference) . '\', \'' . urlencode($content_type) . '\',' . ($is_custom_type ? 1 : 0) . ', 640, 480)">' . __('View video') . '</a>)';
            break;
            // unsupported content. specify download
        // unsupported content. specify download
        default:
            $output .= ' (<a href="' . $bs_url . '" target="new">' . __('Download file') . '</a>)';
    }
    return $output;
}
$mediaType = isset($_REQUEST['media_type']) ? $_REQUEST['media_type'] : NULL;
/*
 * @var     string  indicates whether media type is of custom type
 */
$customType = isset($_REQUEST['custom_type']) ? $_REQUEST['custom_type'] : false;
/*
 * @var     string  contains BLOB reference
 */
$bsReference = isset($_REQUEST['bs_reference']) ? $_REQUEST['bs_reference'] : NULL;
// if media type and BS reference are specified
if (isset($mediaType) && isset($bsReference)) {
    if (isset($customType) && $customType) {
        $bs_file_path = 'bs_disp_as_mime_type.php' . PMA_generate_common_url(array('reference' => $bsReference, 'c_type' => $mediaType));
    } else {
        // Get the BLOB streaming URL
        $bs_file_path = PMA_BS_getURL($bsReference);
        if (empty($bs_file_path)) {
            die(__('No blob streaming server configured!'));
        }
    }
    ?>
<html>
    <head>
    </head>
    <body>
            <?php 
    // supported media types
    switch ($mediaType) {
        // audio content
        case 'audio/mpeg':
            ?>