[BUGFIX] Multiple file upload in ElementBrowser doesn't work 82/27182/4
authorFrans Saris <franssaris@gmail.com>
Fri, 31 Jan 2014 09:51:54 +0000 (10:51 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Fri, 31 Jan 2014 21:14:25 +0000 (22:14 +0100)
The file input fields in the ElementBrowser have the attribute
multiple so you can select multiple files. But as the name
is no array it only uploads 1 file.

This patch changes the name attribute of the file input fields
to an array and shows the flashmessages when an error occurred
during upload.

Resolves: #55497
Releases: 6.2
Change-Id: I1315e35e2ef4cfa8175f962c42f32a5a33ffc16e
Reviewed-on: https://review.typo3.org/27182
Reviewed-by: Ernesto Baschny
Tested-by: Ernesto Baschny
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/core/Classes/Utility/File/ExtendedFileUtility.php
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/t3skin/Resources/Public/Css/visual/element_rte.css

index 504f3df..0525585 100644 (file)
@@ -1908,13 +1908,9 @@ class DocumentTemplate {
                }
                // adding flash messages
                if ($this->showFlashMessages) {
-                       /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
-                       $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
-                       /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
-                       $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
-                       $flashMessages = $defaultFlashMessageQueue->renderFlashMessages();
+                       $flashMessages = $this->getFlashMessages();
                        if (!empty($flashMessages)) {
-                               $markerArray['FLASHMESSAGES'] = '<div id="typo3-messages">' . $flashMessages . '</div>';
+                               $markerArray['FLASHMESSAGES'] = $flashMessages;
                                // If there is no dedicated marker for the messages present
                                // then force them to appear before the content
                                if (strpos($moduleBody, '###FLASHMESSAGES###') === FALSE) {
@@ -1940,6 +1936,23 @@ class DocumentTemplate {
        }
 
        /**
+        * Get the default rendered FlashMessages from queue
+        *
+        * @return string
+        */
+       public function getFlashMessages() {
+               /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
+               $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
+               /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
+               $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+               $flashMessages = $defaultFlashMessageQueue->renderFlashMessages();
+               if (!empty($flashMessages)) {
+                       $flashMessages = '<div id="typo3-messages">' . $flashMessages . '</div>';
+               }
+               return $flashMessages;
+       }
+
+       /**
         * Fill the button lists with the defined HTML
         *
         * @param array $buttons HTML for all buttons
index aa56281..9f7c60b 100644 (file)
@@ -210,7 +210,11 @@ class ExtendedFileUtility extends \TYPO3\CMS\Core\Utility\File\BasicFileUtility
                        if ($this->fileCmdMap['upload']) {
                                $uploads = $this->fileCmdMap['upload'];
                                foreach ($uploads as $upload) {
-                                       if (!$_FILES[('upload_' . $upload['data'])]['name']) {
+                                       if (empty($_FILES[('upload_' . $upload['data'])]['name'])
+                                               || (is_array($_FILES[('upload_' . $upload['data'])]['name'])
+                                                       && empty($_FILES[('upload_' . $upload['data'])]['name'][0])
+                                               )
+                                       ) {
                                                unset($this->fileCmdMap['upload'][$upload['data']]);
                                        }
                                }
index b6f443d..82749d0 100644 (file)
@@ -1369,6 +1369,9 @@ class ElementBrowser {
                } else {
                        $files = '';
                }
+               // Add the FlashMessages if any
+               $content .= $this->doc->getFlashMessages();
+
                // Putting the parts together, side by side:
                $content .= '
 
@@ -2323,7 +2326,7 @@ class ElementBrowser {
                                                <td class="c-wCell c-hCell">';
                // Traverse the number of upload fields (default is 3):
                for ($a = 1; $a <= $count; $a++) {
-                       $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '"' . $this->doc->formWidth(35)
+                       $code .= '<input type="file" multiple="multiple" name="upload_' . $a . '[]"' . $this->doc->formWidth(35)
                                        . ' size="50" />
                                <input type="hidden" name="file[upload][' . $a . '][target]" value="'
                                        . htmlspecialchars($folderObject->getCombinedIdentifier()) . '" />
index c0fda9b..5d7f14c 100644 (file)
@@ -35,6 +35,10 @@ table#typo3-EBfiles tr td.c-wCell {
 body#typo3-browse-links-php a {
        text-decoration: none;
 }
+body#typo3-browse-links-php #typo3-messages {
+       margin: 0px;
+       padding: 10px;
+}
 
 /* - - - - - - - - - - - - - - - - - - - - -
 RTE select image