/** * Loads uploaded file from table change request. * * @param string $key the md5 hash of the column name * @param string $rownumber number of row to process * * @return boolean success * @access public */ public function setUploadedFromTblChangeRequest($key, $rownumber) { if (!isset($_FILES['fields_upload']) || empty($_FILES['fields_upload']['name']['multi_edit'][$rownumber][$key])) { return false; } $file = PMA_File::fetchUploadedFromTblChangeRequestMultiple($_FILES['fields_upload'], $rownumber, $key); // check for file upload errors switch ($file['error']) { // we do not use the PHP constants here cause not all constants // are defined in all versions of PHP - but the correct constants names // are given as comment case 0: //UPLOAD_ERR_OK: return $this->setUploadedFile($file['tmp_name']); break; case 4: //UPLOAD_ERR_NO_FILE: break; case 1: //UPLOAD_ERR_INI_SIZE: $this->_error_message = __('The uploaded file exceeds the upload_max_filesize directive in php.ini.'); break; case 2: //UPLOAD_ERR_FORM_SIZE: $this->_error_message = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'); break; case 3: //UPLOAD_ERR_PARTIAL: $this->_error_message = __('The uploaded file was only partially uploaded.'); break; case 6: //UPLOAD_ERR_NO_TMP_DIR: $this->_error_message = __('Missing a temporary folder.'); break; case 7: //UPLOAD_ERR_CANT_WRITE: $this->_error_message = __('Failed to write file to disk.'); break; case 8: //UPLOAD_ERR_EXTENSION: $this->_error_message = __('File upload stopped by extension.'); break; default: $this->_error_message = __('Unknown error in file upload.'); } // end switch return false; }
/** * @access public * @uses PMA_File::fetchUploadedFromTblChangeRequestMultiple() * @uses PMA_File::setUploadedFile() * @uses PMA_File::$_error_message * @uses $GLOBALS['strUploadErrorIniSize'] * @uses $GLOBALS['strUploadErrorFormSize'] * @uses $GLOBALS['strUploadErrorPartial'] * @uses $GLOBALS['strUploadErrorNoTempDir'] * @uses $GLOBALS['strUploadErrorCantWrite'] * @uses $GLOBALS['strUploadErrorExtension'] * @uses $GLOBALS['strUploadErrorUnknown'] * @uses $_FILES * @param string $key a numeric key used to identify the different rows * @param string $primary_key * @return boolean success */ function setUploadedFromTblChangeRequest($key, $primary = null) { if (!isset($_FILES['fields_upload_' . $key])) { return false; } $file = $_FILES['fields_upload_' . $key]; if (null !== $primary) { $file = PMA_File::fetchUploadedFromTblChangeRequestMultiple($file, $primary); } // check for file upload errors switch ($file['error']) { // cybot_tm: we do not use the PHP constants here cause not all constants // are defined in all versions of PHP - but the correct constants names // are given as comment case 0: //UPLOAD_ERR_OK: return $this->setUploadedFile($file['tmp_name']); break; case 4: //UPLOAD_ERR_NO_FILE: break; case 1: //UPLOAD_ERR_INI_SIZE: $this->_error_message = $GLOBALS['strUploadErrorIniSize']; break; case 2: //UPLOAD_ERR_FORM_SIZE: $this->_error_message = $GLOBALS['strUploadErrorFormSize']; break; case 3: //UPLOAD_ERR_PARTIAL: $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; }
/** * @access public * @uses PMA_File::fetchUploadedFromTblChangeRequestMultiple() * @uses PMA_File::setUploadedFile() * @uses PMA_File::setRecentBLOBReference() * @uses curl_setopt_array() * @uses PMA_File::$_error_message * @uses $GLOBALS['strUploadErrorIniSize'] * @uses $GLOBALS['strUploadErrorFormSize'] * @uses $GLOBALS['strUploadErrorPartial'] * @uses $GLOBALS['strUploadErrorNoTempDir'] * @uses $GLOBALS['strUploadErrorCantWrite'] * @uses $GLOBALS['strUploadErrorExtension'] * @uses $GLOBALS['strUploadErrorUnknown'] * @uses $_FILES * @param string $key a numeric key used to identify the different rows * @param string $primary_key * @return boolean success */ function setUploadedFromTblChangeRequest($key, $primary = null) { if (! isset($_FILES['fields_upload_' . $key])) { return false; } $file = $_FILES['fields_upload_' . $key]; if (null !== $primary) { $file = PMA_File::fetchUploadedFromTblChangeRequestMultiple($file, $primary); } // 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; // if request is an upload to the BLOB repository if ($is_bs_upload) { // load PMA configuration $PMA_Config = $_SESSION['PMA_Config']; // if PMA configuration is 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; // determine 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) { // setup bs variables for uploading $bs_server = $PMA_Config->get('BLOBSTREAMING_SERVER'); $bs_db = $_REQUEST['db']; $bs_table = $_REQUEST['table']; // setup file handle and related variables $tmp_file = fopen($file['tmp_name'], 'r'); $tmp_file_type = $file['type']; $tmp_file_size = $file['size']; if (!$tmp_file_type) $tmp_file_type = NULL; // if none of the required variables contain data, return with an unknown error message 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 init successful 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 CURL options in array $curlOptArr = array( CURLOPT_PUT => TRUE, CURLOPT_HEADER => TRUE, CURLOPT_HTTPHEADER => $customHeader, CURLOPT_INFILESIZE => $tmp_file_size, CURLOPT_INFILE => $tmp_file, CURLOPT_RETURNTRANSFER => TRUE ); // pass array of options to curl handle setup function 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 entire string into array of lines $retArr = explode("\r\n", $ret); // check each line as a valid string of a BLOB reference 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) // check for file upload errors switch ($file['error']) { // cybot_tm: we do not use the PHP constants here cause not all constants // are defined in all versions of PHP - but the correct constants names // are given as comment case 0: //UPLOAD_ERR_OK: return $this->setUploadedFile($file['tmp_name']); break; case 4: //UPLOAD_ERR_NO_FILE: break; case 1: //UPLOAD_ERR_INI_SIZE: $this->_error_message = $GLOBALS['strUploadErrorIniSize']; break; case 2: //UPLOAD_ERR_FORM_SIZE: $this->_error_message = $GLOBALS['strUploadErrorFormSize']; break; case 3: //UPLOAD_ERR_PARTIAL: $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; }
/** * @access public * @uses PMA_File::fetchUploadedFromTblChangeRequestMultiple() * @uses PMA_File::setUploadedFile() * @uses PMA_File::setRecentBLOBReference() * @uses curl_setopt_array() * @uses PMA_File::$_error_message * @uses $_FILES * @param string $key the md5 hash of the column name * @param string $rownumber * @return boolean success */ function setUploadedFromTblChangeRequest($key, $rownumber) { if (!isset($_FILES['fields_upload']) || empty($_FILES['fields_upload']['name']['multi_edit'][$rownumber][$key])) { return false; } $file = PMA_File::fetchUploadedFromTblChangeRequestMultiple($_FILES['fields_upload'], $rownumber, $key); // 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; } // if request is an upload to the BLOB repository if ($is_bs_upload) { $bs_db = $_REQUEST['db']; $bs_table = $_REQUEST['table']; $tmp_filename = $file['tmp_name']; $tmp_file_type = $file['type']; 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) // check for file upload errors switch ($file['error']) { // we do not use the PHP constants here cause not all constants // are defined in all versions of PHP - but the correct constants names // are given as comment case 0: //UPLOAD_ERR_OK: return $this->setUploadedFile($file['tmp_name']); break; case 4: //UPLOAD_ERR_NO_FILE: break; case 1: //UPLOAD_ERR_INI_SIZE: $this->_error_message = __('The uploaded file exceeds the upload_max_filesize directive in php.ini.'); break; case 2: //UPLOAD_ERR_FORM_SIZE: $this->_error_message = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'); break; case 3: //UPLOAD_ERR_PARTIAL: $this->_error_message = __('The uploaded file was only partially uploaded.'); break; case 6: //UPLOAD_ERR_NO_TMP_DIR: $this->_error_message = __('Missing a temporary folder.'); break; case 7: //UPLOAD_ERR_CANT_WRITE: $this->_error_message = __('Failed to write file to disk.'); break; case 8: //UPLOAD_ERR_EXTENSION: $this->_error_message = __('File upload stopped by extension.'); break; default: $this->_error_message = __('Unknown error in file upload.'); } // end switch return false; }