[BUGFIX] Handling file upload fields is broken
authorOliver Hader <oliver@typo3.org>
Tue, 18 Oct 2011 22:43:00 +0000 (00:43 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Sat, 5 Nov 2011 10:08:52 +0000 (11:08 +0100)
The handling of file upload fields in the new system extension
form was broken and not fully implemented. Fetching the
contents, type and size of the file is missing. Besides that,
sending these files via mail was not fully implemented.

Change-Id: I9ad7aa2df1e037f1ac8d50031300af9a030a617c
Fixes: #31085
Releases: 4.7, 4.6
Reviewed-on: http://review.typo3.org/6003
Reviewed-by: Peter Beernink
Tested-by: Peter Beernink
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/form/Classes/Domain/Model/Element/Fileupload.php
typo3/sysext/form/Classes/System/Postprocessor/Mail.php
typo3/sysext/form/Classes/System/Request/Request.php
typo3/sysext/form/Classes/View/Mail/Plain/Element/Fileupload.php
typo3/sysext/form/Configuration/PageTS/modWizards.ts

index 78abc24..20b15f7 100644 (file)
@@ -63,11 +63,33 @@ class tx_form_Domain_Model_Element_Fileupload extends tx_form_Domain_Model_Eleme
        );
 
        /**
+        * Gets the original filename.
+        *
         * @return string
         */
        public function getData() {
                $uploadData = $this->requestHandler->get($this->name);
                return $uploadData['originalFilename'];
        }
+
+       /**
+        * Gets the file type.
+        *
+        * @return string
+        */
+       public function getType() {
+               $uploadData = $this->requestHandler->get($this->name);
+               return $uploadData['type'];
+       }
+
+       /**
+        * Gets the file size.
+        *
+        * @return integer
+        */
+       public function getSize() {
+               $uploadData = $this->requestHandler->get($this->name);
+               return $uploadData['size'];
+       }
 }
 ?>
\ No newline at end of file
index 109f724..f660720 100644 (file)
@@ -89,7 +89,7 @@ class tx_form_System_Postprocessor_Mail {
 
                $this->setHtmlContent();
                $this->setPlainContent();
-               $this->addAttachments();
+               $this->addAttachmentsFromForm();
                $this->send();
 
                return $this->render();
@@ -328,18 +328,34 @@ class tx_form_System_Postprocessor_Mail {
         *
         * @return void
         */
-       protected function addAttachments() {
+       protected function addAttachmentsFromForm() {
                $formElements = $this->form->getElements();
                $values = $this->requestHandler->getByMethod();
+               $this->addAttachmentsFromElements($formElements, $values);
+       }
 
+       /**
+        * Loop through all elements and attach the file when the element
+        * is a fileupload
+        *
+        * @param array $elements
+        * @param array $submittedValues
+        * @return void
+        */
+       protected function addAttachmentsFromElements($elements, $submittedValues) {
                /** @var $element tx_form_Domain_Model_Element_Abstract */
-               foreach ($formElements as $element) {
+               foreach ($elements as $element) {
+                       if (is_a($element, 'tx_form_Domain_Model_Element_Container')) {
+                               $this->addAttachmentsFromElements($element->getElements(), $submittedValues);
+                               continue;
+                       }
                        if (is_a($element, 'tx_form_Domain_Model_Element_Fileupload')) {
                                $elementName = $element->getName();
-                               if (is_array($values[$elementName])) {
-                                       if (file_exists($values[$elementName]['tempFilename'])) {
+                               if (is_array($submittedValues[$elementName]) && isset($submittedValues[$elementName]['tempFilename'])) {
+                                       $filename = $submittedValues[$elementName]['tempFilename'];
+                                       if (is_file($filename) && t3lib_div::isAllowedAbsPath($filename)) {
                                                $this->mailMessage->attach(
-                                                       Swift_Attachment::fromPath($values[$elementName]['tempFilename'])->setFilename($values[$elementName]['originalFilename'])
+                                                       Swift_Attachment::fromPath($filename)->setFilename($submittedValues[$elementName]['originalFilename'])
                                                );
                                        }
                                }
index 952291f..c2fe982 100644 (file)
@@ -308,6 +308,9 @@ class tx_form_System_Request implements t3lib_Singleton {
                        foreach ($_FILES[$this->prefix]['tmp_name'] as $fieldName => $uploadedFile) {
                                if (is_uploaded_file($uploadedFile)) {
                                        $tempFilename = t3lib_div::upload_to_tempfile($uploadedFile);
+                                       if (TYPO3_OS === 'WIN') {
+                                               $tempFilename = t3lib_div::fixWindowsFilePath($tempFilename);
+                                       }
 
                                        if ($tempFilename !== '') {
                                                        // Use finfo to get the mime type
index 13d3658..7e0f15e 100644 (file)
  * @subpackage form
  */
 class tx_form_View_Mail_Plain_Element_Fileupload extends tx_form_View_Mail_Plain_Element_Container {
+       /**
+        * @var tx_form_Domain_Model_Element_Fileupload
+        */
+       protected $model;
 
        /**
         * Constructor
@@ -45,7 +49,7 @@ class tx_form_View_Mail_Plain_Element_Fileupload extends tx_form_View_Mail_Plain
         * @return string
         */
        public function render() {
-               $content = $this->getLabel() . ': ' . $this->getValue();
+               $content = $this->getLabel() . ': ' . $this->model->getValue();
 
                return str_repeat(chr(32), $this->spaces) . $content;
        }
@@ -62,14 +66,5 @@ class tx_form_View_Mail_Plain_Element_Fileupload extends tx_form_View_Mail_Plain
 
                return $label;
        }
-
-       /**
-        * @return mixed
-        */
-       protected function getValue() {
-               $value = $this->model->getAttributeValue('value');
-
-               return $value;
-       }
 }
 ?>
\ No newline at end of file
index 5e0c868..131eab1 100644 (file)
@@ -20,7 +20,7 @@ prefix = tx_form
                                        showAccordions = basic, predefined, content
                                        accordions {
                                                basic {
-                                                       showButtons = checkbox, fieldset, hidden, password, radio, reset, select, submit, textarea, textline
+                                                       showButtons = checkbox, fieldset, fileupload, hidden, password, radio, reset, select, submit, textarea, textline
                                                }
                                                predefined {
                                                        showButtons = email, radiogroup, checkboxgroup, name