blobstreaming.lib.php

来自「phpMyAdmin图形界面化操作,我已经配置好了,只要把解要压缩后的文件放到站」· PHP 代码 · 共 730 行 · 第 1/2 页

PHP
730
字号
{    // if no variables exist in array, return false    if (empty($bs_variables) || count($bs_variables) == 0)        return FALSE;    // set BS variables to those specified in array    foreach ($bs_variables as $key=>$val)        if (!is_null($val) && strlen($val) > 0)        {            // set BS variable to specified value            $query = "SET GLOBAL $key=" . PMA_sqlAddSlashes($val);            $result = PMA_DBI_query($query);            // if query fails execution, return false            if (!$result)                return FALSE;        } // end if (!is_null($val) && strlen($val) > 0)    // return true on success    return TRUE;}/** * returns a list of BLOBStreaming variables used by MySQL * * @access  public * @uses    PMA_Config::get() * @uses    PMA_DBI_query() * @uses    PMA_DBI_fetch_assoc() * @return  array - list of BLOBStreaming variables*/function PMA_BS_GetVariables(){    // load PMA configuration    $PMA_Config = $_SESSION['PMA_Config'];    // return if unable to load PMA configuration    if (empty($PMA_Config))        return NULL;    // run query to retrieve BS variables    $query = "SHOW VARIABLES LIKE '%" . $PMA_Config->get('PBMS_NAME') . "%'";    $result = PMA_DBI_query($query);    $BS_Variables = array();    // while there are records to retrieve    while ($data = @PMA_DBI_fetch_assoc($result))        $BS_Variables[$data['Variable_name']] = $data['Value'];    // return BS variables    return $BS_Variables;}/** * sets the BLOBStreaming global field references to ON/OFF * * @access  public * @param   string - ON or OFF * @uses    PMA_Config::get() * @uses    PMA_sqlAddslashes() * @uses    PMA_DBI_query() * @return  boolean - success/failure of query execution*/function PMA_BS_SetFieldReferences($val){    // load PMA configuration    $PMA_Config = $_SESSION['PMA_Config'];    // return if unable to load PMA configuration    if (empty($PMA_Config))        return FALSE;    // set field references to value specified    $query = "SET GLOBAL " . $PMA_Config->get('PBMS_NAME') . "_field_references=" . PMA_sqlAddslashes($val);    $result = PMA_DBI_try_query($query, null, 0);    // get last known error (if applicable)    PMA_DBI_getError();    // return success of query execution    if ($result && 0 == $GLOBALS['errno'])        return TRUE;    else        return FALSE;}/** * gets the SQL table definition for a given BLOBStreaming table * * @access  public * @param   string - table name * @uses    PMA_Config::get() * @return  string - SQL table definition*/function PMA_BS_GetTableStruct($tbl_name){    // retrieve table structures for BS tables    $bs_tables = $_SESSION['PMA_Config']->get('BLOBSTREAMING_TABLES');       // return if tables don't exist     if (!$bs_tables)        return;    // return if specified table doesn't exist in collection of BS tables    if (!isset($bs_tables[$tbl_name]))        return;    // return specified table's structure    return $bs_tables[$tbl_name]['struct'];}/** * creates the BLOBStreaming tables for a given database * * @access  public * @param   string - database name * @uses    PMA_Config::get() * @uses    PMA_DBI_select_db() * @uses    PMA_DBI_query() * @uses    PMA_BS_GetTableStruct() * @return  boolean - success/failure of transactional query execution*/function PMA_BS_CreateTables($db_name){    // retrieve BS tables    $bs_tables = $_SESSION['PMA_Config']->get('BLOBSTREAMING_TABLES');    // select specified database    PMA_DBI_select_db($db_name);    // create necessary BS tables for specified database    foreach ($bs_tables as $table_key=>$table)    {        $result = PMA_DBI_query(PMA_BS_GetTableStruct($table_key));        // return false if query execution fails        if (!$result)            return FALSE;    }    // return true on success    return TRUE;}/** * drops BLOBStreaming tables for a given database * * @access  public * @param   string - database name * @uses    PMA_Config::get() * @uses    PMA_DBI_select_db() * @uses    PMA_backquote() * @uses    PMA_DBI_query() * @return  boolean - success/failure of transactional query execution*/function PMA_BS_DropTables($db_name){    // load PMA configuration    $PMA_Config = $_SESSION['PMA_Config'];    // return if unable to load PMA configuration    if (empty($PMA_Config))        return FALSE;    // retrieve BS tables    $bs_tables = $PMA_Config->get('BLOBSTREAMING_TABLES');    // select specified database    PMA_DBI_select_db($db_name);    // drop BS tables    foreach ($bs_tables as $table_key=>$table)    {        $query = "DROP TABLE IF EXISTS " . PMA_backquote($table_key);        $result = PMA_DBI_query($query);        // return false if query execution fails        if (!$result)            return FALSE;    }    // return true on success    return TRUE;}/** * returns the field name for a primary key of a given table in a given database * * @access  public * @param   string - database name * @param   string - table name * @uses    PMA_DBI_select_db() * @uses    PMA_backquote() * @uses    PMA_DBI_query() * @uses    PMA_DBI_fetch_assoc() * @return  string - field name for primary key*/function PMA_BS_GetPrimaryField($db_name, $tbl_name){    // load PMA configuration    $PMA_Config = $_SESSION['PMA_Config'];    // return if unable to load PMA configuration    if (empty($PMA_Config))        return FALSE;    // select specified database    PMA_DBI_select_db($db_name);    // retrieve table fields    $query = "SHOW FULL FIELDS FROM " . PMA_backquote($tbl_name);    $result = PMA_DBI_query($query);    // while there are records to parse    while ($data = PMA_DBI_fetch_assoc($result))        if ("PRI" == $data['Key'])            return $data['Field'];    // return NULL on no primary key    return NULL;}/** * checks whether a BLOB reference exists in the BLOB repository * * @access  public * @param   string - BLOB reference * @param   string - database name * @uses    PMA_DBI_select_db() * @uses    PMA_backquote() * @uses    PMA_Config::get() * @uses    PMA_sqlAddslashes() * @uses    PMA_DBI_query() * @return  boolean - existence of BLOB reference*/function PMA_BS_ReferenceExists($bs_reference, $db_name){    $referenceExists = FALSE;    // return false on invalid BS reference    if (strlen ($bs_reference) < strlen ("~*$db_name/~") || "~*$db_name/~" != substr ($bs_reference, 0, strlen ($db_name) + 4))        return $referenceExists;    // load PMA configuration    $PMA_Config = $_SESSION['PMA_Config'];    // return if unable to load PMA configuration    if (empty($PMA_Config))        return $referenceExists;    // select specified database    PMA_DBI_select_db($db_name);    // run query on BS reference retrieval    $query = "SELECT * FROM " . PMA_backquote($PMA_Config->get('PBMS_NAME') . "_reference") . " WHERE Blob_url='" . PMA_sqlAddslashes($bs_reference) . "'";    $result = PMA_DBI_query($query);    // if record exists    if ($data = @PMA_DBI_fetch_assoc($result))        $referenceExists = TRUE;    // return reference existance    return $referenceExists;}/** * creates a HTTP link to a given blob reference for a given database * * @access  public * @param   string - BLOB reference * @param   string - database name * @uses    PMA_Config::get() * @uses    PMA_DBI_select_db() * @uses    PMA_backquote() * @uses    PMA_sqlAddslashes() * @uses    PMA_DBI_query() * @uses    PMA_DBI_fetch_assoc() * @return  string - HTTP link or Error*/function PMA_BS_CreateReferenceLink($bs_reference, $db_name){    // load PMA configuration    $PMA_Config = $_SESSION['PMA_Config'];    // return if unable to load PMA configuration    if (empty($PMA_Config))        return '';    // generate bs reference link    $bs_ref_link = 'http://' . $PMA_Config->get('BLOBSTREAMING_SERVER') . '/' . $bs_reference;    // select specified database    PMA_DBI_select_db($db_name);    $pbms_repo_bq = PMA_backquote($PMA_Config->get('PBMS_NAME') . "_repository");    $pbms_ref_bq = PMA_backquote($PMA_Config->get('PBMS_NAME') . "_reference");    $pbms_cust_content_bq = PMA_backquote($PMA_Config->get('PBMS_NAME') . "_custom_content_type");    // run query on determining specified BS reference    $query = "SELECT $pbms_repo_bq.Content_type, $pbms_cust_content_bq.Content_type AS Custom_type";    $query .= " FROM $pbms_repo_bq LEFT JOIN $pbms_ref_bq ON";    $query .= "$pbms_repo_bq.Repository_id=$pbms_ref_bq.Repository_id";    $query .= " AND $pbms_repo_bq.Blob_size=$pbms_ref_bq.Blob_size";    $query .= " AND $pbms_repo_bq.Repo_blob_offset=$pbms_ref_bq.Repo_blob_offset";    $query .= " LEFT JOIN $pbms_cust_content_bq ON $pbms_cust_content_bq.Blob_url=$pbms_ref_bq.Blob_url";    $query .= " WHERE $pbms_ref_bq.Blob_url='" . PMA_sqlAddslashes($bs_reference) . "'";    $result = PMA_DBI_query($query);    // if record exists    if ($data = @PMA_DBI_fetch_assoc($result))    {        // determine content-type for BS repository file (original or custom)	$is_custom_type = false;	if (isset($data['Custom_type']))	{	        $content_type = $data['Custom_type'];		$is_custom_type = true;	}	else		$content_type = $data['Content_type'];        if (!$content_type)            $content_type = NULL;        $output = "<a href=\"#\" onclick=\"requestMIMETypeChange('" . urlencode($db_name) . "', '" . urlencode($GLOBALS['table']) . "', '" . urlencode($bs_reference) . "', '" . urlencode($content_type) . "')\">$content_type</a>";        // specify custom HTML for various content types        switch ($content_type)        {            // no content specified            case NULL:                $output = "NULL";                break;            // image content            case 'image/jpeg':            case 'image/png':                $output .= ' (<a href="' . $bs_ref_link . '" target="new">' . $GLOBALS['strViewImage'] . '</a>)';                break;            // 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)">' . $GLOBALS['strPlayAudio']. '</a>)';                break;            // 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)">' . $GLOBALS['strViewVideo'] . '</a>)';                break;            // unsupported content. specify download            default:                $output .= ' (<a href="' . $bs_ref_link . '" target="new">' . $GLOBALS['strDownloadFile']. '</a>)';        }        // return HTML        return $output;    } // end if ($data = @PMA_DBI_fetch_assoc($result))    // return on error    return 'Error';}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?