/** * sets the name if the file to the one selected in the tbl_change form * * @access public * @uses $_REQUEST * @uses PMA_File::setLocalSelectedFile() * @uses is_string() * @param string $key a numeric key used to identify the different rows * @param string $primary_key * @return boolean success */ function setSelectedFromTblChangeRequest($key, $primary = null) { if (null !== $primary) { if (! empty($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]) && is_string($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary])) { // ... whether with multiple rows ... // rajk - for blobstreaming $is_bs_upload = FALSE; // check if this field requires a repository upload if (isset($_REQUEST['upload_blob_repo_' . $key])) $is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE; // is a request to upload file to BLOB repository using uploadDir mechanism if ($is_bs_upload) { // load PMA configuration $PMA_Config = $_SESSION['PMA_Config']; // if the PMA configuration was loaded if (!empty($PMA_Config)) { // load BS variables from PMA configuration $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'); $curlExists = $PMA_Config->get('CURL_EXISTS'); $bs_database = $PMA_Config->get('BLOBSTREAMABLE_DATABASES'); $bs_database = $bs_database[$_REQUEST['db']]; $allBSTablesExist = TRUE; // if plugins and curl exist if ($pluginsExist && $curlExists) { foreach ($bs_database as $table_key=>$table) { if (!$bs_database[$table_key]['Exists']) { $allBSTablesExist = FALSE; break; } } } else $allBSTablesExist = FALSE; // if necessary BS tables exist if ($allBSTablesExist) { // load BS variables $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER'); $bs_db = $_REQUEST['db']; $bs_table = $_REQUEST['table']; // setup uploadDir mechanism and file variables $tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]; $tmp_file = fopen($tmp_filename, 'r'); $tmp_file_size = filesize($tmp_filename); // check if fileinfo library exists if ($PMA_Config->get('FILEINFO_EXISTS')) { // attempt to init fileinfo $finfo = finfo_open(FILEINFO_MIME); // fileinfo exists if ($finfo) { // pass in filename to fileinfo and close fileinfo handle after $tmp_file_type = finfo_file($finfo, $tmp_filename); finfo_close($finfo); } } else // no fileinfo library exists, use file command $tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename)); if (!$tmp_file_type) $tmp_file_type = NULL; // necessary variables aren't loaded, return error message (unknown error) if (!$bs_server || !$bs_db || !$bs_table || !$tmp_file || !$tmp_file_size) { $this->_error_message = $GLOBALS['strUploadErrorUnknown']; return FALSE; } else $bs_server_path = 'http://' . $bs_server . '/' . $bs_db . '/' . $bs_table; // init curl handle $curlHnd = curl_init ($bs_server_path); // curl handle exists if ($curlHnd) { // specify custom header $customHeader = array( "Accept-Language: en-us;en;q=0;5", "Accept-Charset: ISO-8859-1;utf-8;q=0.7,*;q=0.7", "Content-type: $tmp_file_type" ); // specify custom curl options $curlOptArr = array( CURLOPT_PUT => TRUE, CURLOPT_HEADER => TRUE, CURLOPT_HTTPHEADER => $customHeader, CURLOPT_INFILESIZE => $tmp_file_size, CURLOPT_INFILE => $tmp_file, CURLOPT_RETURNTRANSFER => TRUE ); // setup custom curl options (as specified in above array) curl_setopt_array($curlHnd, $curlOptArr); // execute curl request and retrieve error message(s) (if any) $ret = curl_exec($curlHnd); $errRet = curl_error($curlHnd); // close curl handle curl_close($curlHnd); // split return string into lines $retArr = explode("\r\n", $ret); // check subsequent lines for valid BLOB reference string foreach ($retArr as $value) if (strlen($value) > strlen("~*$bs_db/~") && "~*$bs_db/~" == substr($value, 0, strlen($bs_db) + 4)) { // is a valid reference, so set as current and break PMA_File::setRecentBLOBReference($value); break; } // close file handle if ($tmp_file) fclose($tmp_file); } // end if ($curlHnd) } // end if ($allBSTablesExist) } // end if ($PMA_Config) } // end if ($is_bs_upload) return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]); } else { return false; } } elseif (! empty($_REQUEST['fields_uploadlocal_' . $key]) && is_string($_REQUEST['fields_uploadlocal_' . $key])) { // rajk - for blobstreaming $is_bs_upload = FALSE; // check if this field requires a repository upload if (isset($_REQUEST['upload_blob_repo_' . $key])) $is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE; // is a request to upload file to BLOB repository using uploadDir mechanism if ($is_bs_upload) { // load PMA configuration $PMA_Config = $_SESSION['PMA_Config']; // if the PMA configuration was loaded if (!empty($PMA_Config)) { // load BS variables from PMA configuration $pluginsExist = $PMA_Config->get('BLOBSTREAMING_PLUGINS_EXIST'); $curlExists = $PMA_Config->get('CURL_EXISTS'); $bs_database = $PMA_Config->get('BLOBSTREAMABLE_DATABASES'); $bs_database = $bs_database[$_REQUEST['db']]; $allBSTablesExist = TRUE; // if plugins and curl exist if ($pluginsExist && $curlExists) { foreach ($bs_database as $table_key=>$table) { if (!$bs_database[$table_key]['Exists']) { $allBSTablesExist = FALSE; break; } } } else $allBSTablesExist = FALSE; if ($allBSTablesExist) { // load BS variables $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER'); $bs_db = $_REQUEST['db']; $bs_table = $_REQUEST['table']; // setup uploadDir mechanism and file variables $tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$primary]; $tmp_file = fopen($tmp_filename, 'r'); $tmp_file_size = filesize($tmp_filename); // check if fileinfo library exists if ($PMA_Config->get('FILEINFO_EXISTS')) { // attempt to init fileinfo $finfo = finfo_open(FILEINFO_MIME); // if fileinfo exists if ($finfo) { // pass in filename to fileinfo and close fileinfo handle after $tmp_file_type = finfo_file($finfo, $tmp_filename); finfo_close($finfo); } } else // no fileinfo library exists, use file command $tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename)); if (!$tmp_file_type) $tmp_file_type = NULL; // necessary variables aren't loaded, return error message (unknown error) if (!$bs_server || !$bs_db || !$bs_table || !$tmp_file || !$tmp_file_size) { $this->_error_message = $GLOBALS['strUploadErrorUnknown']; return FALSE; } else $bs_server_path = 'http://' . $bs_server . '/' . $bs_db . '/' . $bs_table; // init curl handle $curlHnd = curl_init ($bs_server_path); // if curl handle exists if ($curlHnd) { // specify custom header $customHeader = array( "Accept-Language: en-us;en;q=0;5", "Accept-Charset: ISO-8859-1;utf-8;q=0.7,*;q=0.7", "Content-type: $tmp_file_type" ); // specify custom curl options $curlOptArr = array( CURLOPT_PUT => TRUE, CURLOPT_HEADER => TRUE, CURLOPT_HTTPHEADER => $customHeader, CURLOPT_INFILESIZE => $tmp_file_size, CURLOPT_INFILE => $tmp_file, CURLOPT_RETURNTRANSFER => TRUE ); // setup custom curl options (as specified in above array) curl_setopt_array($curlHnd, $curlOptArr); // execute curl request and retrieve error message(s) (if any) $ret = curl_exec($curlHnd); $errRet = curl_error($curlHnd); // close curl handle curl_close($curlHnd); // split return string into lines $retArr = explode("\r\n", $ret); // check subsequent lines for valid BLOB reference string foreach ($retArr as $value) if (strlen($value) > strlen("~*$bs_db/~") && "~*$bs_db/~" == substr($value, 0, strlen($bs_db) + 4)) { // is a valid reference, so set as current and break PMA_File::setRecentBLOBReference($value); break; } // close file handle if ($tmp_file) fclose($tmp_file); } // end if ($curlHnd) } // end if ($allBSTablesExist) } // end if ($PMA_Config) } // end if ($is_bs_upload) return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal_' . $key]); } return false; }
/** * sets the name if the file to the one selected in the tbl_change form * * @access public * @uses $_REQUEST * @uses PMA_File::setLocalSelectedFile() * @uses is_string() * @param string $key the md5 hash of the column name * @param string $rownumber * @return boolean success */ function setSelectedFromTblChangeRequest($key, $rownumber = null) { if (!empty($_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key]) && is_string($_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key])) { // ... whether with multiple rows ... // for blobstreaming $is_bs_upload = FALSE; // check if this field requires a repository upload if (isset($_REQUEST['upload_blob_repo']['multi_edit'][$rownumber][$key])) { $is_bs_upload = $_REQUEST['upload_blob_repo']['multi_edit'][$rownumber][$key] == "on" ? TRUE : FALSE; } // is a request to upload file to BLOB repository using uploadDir mechanism if ($is_bs_upload) { $bs_db = $_REQUEST['db']; $bs_table = $_REQUEST['table']; $tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$rownumber]; // check if fileinfo library exists if ($PMA_Config->get('FILEINFO_EXISTS')) { // attempt to init fileinfo $finfo = finfo_open(FILEINFO_MIME); // fileinfo exists if ($finfo) { // pass in filename to fileinfo and close fileinfo handle after $tmp_file_type = finfo_file($finfo, $tmp_filename); finfo_close($finfo); } } else { // no fileinfo library exists, use file command $tmp_file_type = exec("file -bi " . escapeshellarg($tmp_filename)); } if (!$tmp_file_type) { $tmp_file_type = NULL; } if (!$bs_db || !$bs_table) { $this->_error_message = $GLOBALS['strUploadErrorUnknown']; return FALSE; } $blob_url = PMA_BS_UpLoadFile($bs_db, $bs_table, $tmp_file_type, $tmp_filename); PMA_File::setRecentBLOBReference($blob_url); } // end if ($is_bs_upload) return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key]); } else { return false; } }