TYPO3 CMS  TYPO3_6-2
FileUploadController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
27  // Internal, static:
34  public $doc;
35 
36  // Name of the filemount
40  public $title;
41 
42  // Internal, static (GPVar):
43  // Set with the target path inputted in &target
47  public $target;
48 
49  // Return URL of list module.
53  public $returnUrl;
54 
55  // Internal, dynamic:
56  // Accumulating content
60  public $content;
61 
67  protected $folderObject;
68 
72  public function __construct() {
73  $GLOBALS['SOBE'] = $this;
74  $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
75  $GLOBALS['BACK_PATH'] = '';
76 
77  $this->init();
78  }
79 
85  protected function init() {
86  // Initialize GPvars:
87  $this->target = GeneralUtility::_GP('target');
88  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
89  if (!$this->returnUrl) {
90  $this->returnUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . BackendUtility::getModuleUrl('file_list') . '&id=' . rawurlencode($this->target);
91  }
92  // Create the folder object
93  if ($this->target) {
94  $this->folderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->target);
95  }
96  if ($this->folderObject->getStorage()->getUid() === 0) {
97  throw new \TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException('You are not allowed to access folders outside your storages', 1375889834);
98  }
99 
100  // Cleaning and checking target directory
101  if (!$this->folderObject) {
102  $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:paramError', TRUE);
103  $message = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xlf:targetNoDir', TRUE);
104  throw new \RuntimeException($title . ': ' . $message, 1294586843);
105  }
106  // Setting the title and the icon
107  $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-filetree-root');
108  $this->title = $icon . htmlspecialchars($this->folderObject->getStorage()->getName()) . ': ' . htmlspecialchars($this->folderObject->getIdentifier());
109  // Setting template object
110  $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
111  $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/file_upload.html');
112  $this->doc->backPath = $GLOBALS['BACK_PATH'];
113  $this->doc->form = '<form action="tce_file.php" method="post" name="editform" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
114  }
115 
121  public function main() {
122  // Make page header:
123  $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle'));
124  $form = $this->renderUploadForm();
125  $pageContent = $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.pagetitle')) . $this->doc->section('', $form);
126  // Header Buttons
127  $docHeaderButtons = array(
128  'csh' => BackendUtility::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH']),
129  'back' => ''
130  );
131  $markerArray = array(
132  'CSH' => $docHeaderButtons['csh'],
133  'FUNC_MENU' => BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
134  'CONTENT' => $pageContent,
135  'PATH' => $this->title
136  );
137  // Back
138  if ($this->returnUrl) {
139  $docHeaderButtons['back'] = '<a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisUrl($this->returnUrl)) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
140  }
141  $this->content .= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
142  $this->content .= $this->doc->endPage();
143  $this->content = $this->doc->insertStylesAndJS($this->content);
144  }
145 
152  public function renderUploadForm() {
153  // Make checkbox for "overwrite"
154  $content = '
155  <div id="c-override">
156  <p><label for="overwriteExistingFiles"><input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> ' . $GLOBALS['LANG']->getLL('overwriteExistingFiles', 1) . '</label></p>
157  <p>&nbsp;</p>
158  <p>' . $GLOBALS['LANG']->getLL('uploadMultipleFilesInfo', TRUE) . '</p>
159  </div>
160  ';
161  // Produce the number of upload-fields needed:
162  $content .= '
163  <div id="c-upload">
164  ';
165  // Adding 'size="50" ' for the sake of Mozilla!
166  $content .= '
167  <input type="file" multiple="true" name="upload_1[]" />
168  <input type="hidden" name="file[upload][1][target]" value="' . htmlspecialchars($this->folderObject->getCombinedIdentifier()) . '" />
169  <input type="hidden" name="file[upload][1][data]" value="1" /><br />
170  ';
171  $content .= '
172  </div>
173  ';
174  // Submit button:
175  $content .= '
176  <div id="c-submit">
177  <input type="hidden" name="redirect" value="' . $this->returnUrl . '" /><br />
179  <input type="submit" value="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:file_upload.php.submit', TRUE) . '" />
180  </div>
181  ';
182  return $content;
183  }
184 
190  public function printContent() {
191  echo $this->content;
192  }
193 
194 }
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
static getModuleUrl($moduleName, $urlParameters=array(), $backPathOverride=FALSE, $returnAbsoluteUrl=FALSE)
static getHiddenTokenField($formName='securityToken', $tokenName='formToken')
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script='', $addparams='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static linkThisUrl($url, array $getParams=array())