📄 file.class.php
字号:
$this->_error_message = $GLOBALS['strUploadErrorPartial']; break; case 6: //UPLOAD_ERR_NO_TMP_DIR: $this->_error_message = $GLOBALS['strUploadErrorNoTempDir']; break; case 7: //UPLOAD_ERR_CANT_WRITE: $this->_error_message = $GLOBALS['strUploadErrorCantWrite']; break; case 8: //UPLOAD_ERR_EXTENSION: $this->_error_message = $GLOBALS['strUploadErrorExtension']; break; default: $this->_error_message = $GLOBALS['strUploadErrorUnknown']; } // end switch return false; } /** * strips some dimension from the multi-dimensional array from $_FILES * * <code> * $file['name']['multi_edit'][$primary] = [value] * $file['type']['multi_edit'][$primary] = [value] * $file['size']['multi_edit'][$primary] = [value] * $file['tmp_name']['multi_edit'][$primary] = [value] * $file['error']['multi_edit'][$primary] = [value] * * // becomes: * * $file['name'] = [value] * $file['type'] = [value] * $file['size'] = [value] * $file['tmp_name'] = [value] * $file['error'] = [value] * </code> * * @todo re-check if requirements changes to PHP >= 4.2.0 * @access public * @static * @param array $file the array * @param string $primary * @return array */ function fetchUploadedFromTblChangeRequestMultiple($file, $primary) { $new_file = array( 'name' => $file['name']['multi_edit'][$primary], 'type' => $file['type']['multi_edit'][$primary], 'size' => $file['size']['multi_edit'][$primary], 'tmp_name' => $file['tmp_name']['multi_edit'][$primary], 'error' => $file['error']['multi_edit'][$primary], ); return $new_file; } /** * 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; } /** * @access public * @uses PMA_File->$_error_message as return value * @return string error message */ function getError() { return $this->_error_message; } /** * @access public * @uses PMA_File->$_error_message to check it * @return boolean whether an error occured or not */ function isError() { return ! empty($this->_error_message); } /** * checks the superglobals provided if the tbl_change form is submitted * and uses the submitted/selected file * * @access public * @uses PMA_File::setUploadedFromTblChangeRequest() * @uses PMA_File::setSelectedFromTblChangeRequest() * @param string $key a numeric key used to identify the different rows * @param string $primary_key * @return boolean success */ function checkTblChangeForm($key, $primary_key) { if ($this->setUploadedFromTblChangeRequest($key, $primary_key)) { // well done ... $this->_error_message = ''; return true;/* } elseif ($this->setUploadedFromTblChangeRequest($key)) { // well done ... $this->_error_message = ''; return true;*/ } elseif ($this->setSelectedFromTblChangeRequest($key, $primary_key)) { // well done ... $this->_error_message = ''; return true;/* } elseif ($this->setSelectedFromTblChangeRequest($key)) { // well done ... $this->_error_message = ''; return true;*/ } // all failed, whether just no file uploaded/selected or an error return false; } /** * * @access public * @uses $GLOBALS['strFileCouldNotBeRead'] * @uses PMA_File::setName() * @uses PMA_securePath() * @uses PMA_userDir()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -