diff --git a/core/includes/file.inc b/core/includes/file.inc index 7d907cf..0c320fb 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -1067,12 +1067,9 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, global $user; static $upload_cache; - // Prepare uploaded files info. Representation is slightly different - // for multiple uploads and we fix that here. - $uploaded_files = $_FILES; - if (!is_array($uploaded_files['files']['name'][$source])) { - foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $value) - $uploaded_files['files'][$value][$source] = array($uploaded_files['files'][$value][$source]); + // Make sure there's an upload to process. + if (empty($_FILES['files']['name'][$source])) { + return NULL; } // Return cached objects without processing since the file will have @@ -1084,9 +1081,12 @@ function file_save_upload($source, $validators = array(), $destination = FALSE, return $upload_cache[$source]; } - // Make sure there's an upload to process. - if (empty($uploaded_files['files']['name'][$source][0])) { - return NULL; + // Prepare uploaded files info. Representation is slightly different + // for multiple uploads and we fix that here. + $uploaded_files = $_FILES; + if (!is_array($uploaded_files['files']['name'][$source])) { + foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $value) + $uploaded_files['files'][$value][$source] = array($uploaded_files['files'][$value][$source]); } $files = array(); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index c2d922d..855cec3 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -148,7 +148,12 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, } // Attach a file to the node. - $edit['files[' . $field_name . '_' . $langcode . '_0]'] = drupal_realpath($file->uri); + $field = field_info_field($field_name); + $name = 'files[' . $field_name . '_' . $langcode . '_0]'; + if ($field['cardinality'] != 1) { + $name .= '[]'; + } + $edit[$name] = drupal_realpath($file->uri); $this->drupalPost("node/$nid/edit", $edit, t('Save and keep published')); return $nid; diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index b29144e..440840f 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -113,7 +113,7 @@ function testMultiValuedWidget() { $this->drupalGet("node/add/$type_name"); foreach (array($field_name2, $field_name) as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { - $edit = array('files[' . $each_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $delta . ']' => drupal_realpath($test_file->uri)); + $edit = array('files[' . $each_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $delta . '][]' => drupal_realpath($test_file->uri)); // If the Upload button doesn't exist, drupalPost() will automatically // fail with an assertion message. $this->drupalPost(NULL, $edit, t('Upload')); @@ -272,7 +272,7 @@ function testPrivateFileComment() { // Add a comment with a file. $text_file = $this->getTestFile('text'); $edit = array( - 'files[field_' . $name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . 0 . '][]' => drupal_realpath($text_file->uri), + 'files[field_' . $name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($text_file->uri), 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $comment_body = $this->randomName(), ); $this->drupalPost(NULL, $edit, t('Save'));