TYPO3 CMS  TYPO3_8-7
FileUpload.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 
26 class FileUpload extends AbstractNode
27 {
33  public function render(): array
34  {
35  $backendUser = $this->getBackendUserAuthentication();
36  $result = $this->initializeResultArray();
37 
38  $parameterArray = $this->data['parameterArray'];
39  $itemName = $parameterArray['itemFormElName'];
40  $uploadFieldId = $parameterArray['itemFormElID'] . '_files';
41  $config = $parameterArray['fieldConf']['config'];
42  $maxItems = $config['maxitems'];
43  $isDirectFileUploadEnabled = (bool)$backendUser->uc['edit_docModuleUpload'];
44 
45  if (!isset($config['internal_type'])
46  || $config['internal_type'] !== 'file'
47  || !$isDirectFileUploadEnabled
48  || empty($config['uploadfolder'])
49  ) {
50  // No upload if disabled for user or upload folder missing
51  return $result;
52  }
53 
54  if ($maxItems === 1) {
55  // If maxItems = 1 then automatically replace the current item file selector
56  $resultArray['additionalJavaScriptPost'][] =
57  'TBE_EDITOR.clearBeforeSettingFormValueFromBrowseWin[' . GeneralUtility::quoteJSvalue($itemName) . '] = {'
58  . 'itemFormElID_file: ' . GeneralUtility::quoteJSvalue($uploadFieldId)
59  . '}';
60  }
61 
62  // Insert the multiple attribute to enable HTML5 multiple file upload
63  $selectorMultipleAttribute = '';
64  $multipleFilenameSuffix = '';
65  if ($maxItems > 1) {
66  $selectorMultipleAttribute = ' multiple="multiple"';
67  $multipleFilenameSuffix = '[]';
68  }
69 
70  $html= [];
71  $html[] = '<div id="' . $uploadFieldId . '">';
72  $html[] = '<input';
73  $html[] = ' type="file"';
74  $html[] = $selectorMultipleAttribute;
75  $html[] = ' name="data_files' . $this->data['elementBaseName'] . $multipleFilenameSuffix . '"';
76  $html[] = ' size="35"';
77  $html[] = ' onchange="' . implode('', $parameterArray['fieldChangeFunc']) . '"';
78  $html[] = '/>';
79  $html[] = '</div>';
80 
81  $result['html'] = implode(LF, $html);
82  return $result;
83  }
84 
88  protected function getBackendUserAuthentication()
89  {
90  return $GLOBALS['BE_USER'];
91  }
92 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']