From f30125fcd3c0cf2f4d80997c8dc2332311cfc12c Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Mon, 6 Dec 2010 12:49:08 -0500 Subject: [PATCH] Continue insertion did not work if the form had special controls like file upload from client, file upload from server or BLOB streaming upload --- libraries/File.class.php | 171 ++++++++++++--------------------------- tbl_change.php | 6 +- 2 files changed, 56 insertions(+), 121 deletions(-) diff --git a/libraries/File.class.php b/libraries/File.class.php index 2c59179f5..c093a7be3 100644 --- a/libraries/File.class.php +++ b/libraries/File.class.php @@ -263,24 +263,19 @@ class PMA_File * @param string $rownumber * @return boolean success */ - function setUploadedFromTblChangeRequest($key, $rownumber = null) + function setUploadedFromTblChangeRequest($key, $rownumber) { - if (! isset($_FILES['fields_upload_' . $key])) { + if (! isset($_FILES['fields_upload']) && ! isset($_FILES['fields_upload']['name']['multi_edit'][$rownumber][$key])) { return false; } - - $file = $_FILES['fields_upload_' . $key]; - - if (null !== $rownumber) { - $file = PMA_File::fetchUploadedFromTblChangeRequestMultiple($file, $rownumber); - } + $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_' . $key])) { - $is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE; + 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) { @@ -340,11 +335,11 @@ class PMA_File * strips some dimension from the multi-dimensional array from $_FILES * * - * $file['name']['multi_edit'][$rownumber] = [value] - * $file['type']['multi_edit'][$rownumber] = [value] - * $file['size']['multi_edit'][$rownumber] = [value] - * $file['tmp_name']['multi_edit'][$rownumber] = [value] - * $file['error']['multi_edit'][$rownumber] = [value] + * $file['name']['multi_edit'][$rownumber][$key] = [value] + * $file['type']['multi_edit'][$rownumber][$key] = [value] + * $file['size']['multi_edit'][$rownumber][$key] = [value] + * $file['tmp_name']['multi_edit'][$rownumber][$key] = [value] + * $file['error']['multi_edit'][$rownumber][$key] = [value] * * // becomes: * @@ -360,16 +355,17 @@ class PMA_File * @static * @param array $file the array * @param string $rownumber + * @param string $key * @return array */ - function fetchUploadedFromTblChangeRequestMultiple($file, $rownumber) + function fetchUploadedFromTblChangeRequestMultiple($file, $rownumber, $key) { $new_file = array( - 'name' => $file['name']['multi_edit'][$rownumber], - 'type' => $file['type']['multi_edit'][$rownumber], - 'size' => $file['size']['multi_edit'][$rownumber], - 'tmp_name' => $file['tmp_name']['multi_edit'][$rownumber], - 'error' => $file['error']['multi_edit'][$rownumber], + 'name' => $file['name']['multi_edit'][$rownumber][$key], + 'type' => $file['type']['multi_edit'][$rownumber][$key], + 'size' => $file['size']['multi_edit'][$rownumber][$key], + 'tmp_name' => $file['tmp_name']['multi_edit'][$rownumber][$key], + 'error' => $file['error']['multi_edit'][$rownumber][$key], ); return $new_file; @@ -388,104 +384,55 @@ class PMA_File */ function setSelectedFromTblChangeRequest($key, $rownumber = null) { - if (null !== $rownumber) { - if (! empty($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$rownumber]) - && is_string($_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$rownumber])) { - // ... whether with multiple rows ... - // 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) { - $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_' . $key]['multi_edit'][$rownumber]); - } else { - return false; - } - } elseif (! empty($_REQUEST['fields_uploadlocal_' . $key]) - && is_string($_REQUEST['fields_uploadlocal_' . $key])) { + 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_' . $key])) - $is_bs_upload = ($_REQUEST['upload_blob_repo_' . $key]['multi_edit'][0] == "on") ? TRUE : FALSE; + 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) - { - // check if fileinfo library exists - if ($PMA_Config->get('FILEINFO_EXISTS')) - { - // attempt to init fileinfo - $finfo = finfo_open(FILEINFO_MIME); + if ($is_bs_upload) { + $bs_db = $_REQUEST['db']; + $bs_table = $_REQUEST['table']; + $tmp_filename = $GLOBALS['cfg']['UploadDir'] . '/' . $_REQUEST['fields_uploadlocal_' . $key]['multi_edit'][$rownumber]; - // 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)); + // check if fileinfo library exists + if ($PMA_Config->get('FILEINFO_EXISTS')) { + // attempt to init fileinfo + $finfo = finfo_open(FILEINFO_MIME); - if (!$tmp_file_type) - $tmp_file_type = NULL; + // 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)); + } - $bs_db = $_REQUEST['db']; - $bs_table = $_REQUEST['table']; - 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); + 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_' . $key]); + return $this->setLocalSelectedFile($_REQUEST['fields_uploadlocal']['multi_edit'][$rownumber][$key]); + } else { + return false; } - - return false; } /** @@ -525,22 +472,10 @@ class PMA_File // well done ... $this->_error_message = ''; return true; -/* - } elseif ($this->setUploadedFromTblChangeRequest($key)) { - // well done ... - $this->_error_message = ''; - return true; -*/ } elseif ($this->setSelectedFromTblChangeRequest($key, $rownumber)) { // 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 diff --git a/tbl_change.php b/tbl_change.php index bee7017c8..edbddb00e 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -889,11 +889,11 @@ foreach ($rows as $row_id => $vrow) { // check if field type is of longblob and if the table is PBMS enabled. if (($field['pma_type'] == "longblob") && PMA_BS_IsTablePBMSEnabled($db, $table, $tbl_type)) { echo '
'; - echo ' ' . __('Upload to BLOB repository'); + echo ' ' . __('Upload to BLOB repository'); } echo '
'; - echo ' '; + echo ' '; // find maximum upload size, based on field type /** @@ -926,7 +926,7 @@ foreach ($rows as $row_id => $vrow) { } elseif (!empty($files)) { echo "
\n"; echo ' ' . __('Or') . '' . ' ' . __('web server upload directory') . ':
' . "\n"; - echo ' ' . "\n"; echo ' ' . "\n"; echo $files; echo ' ' . "\n";