/** * Checks if a file has been uploaded. If so, create a File object and return it. * * @return File|NULL */ protected function checkUpload() { $file = GeneralUtility::_GP('file'); // Initializing: $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcessor->setActionPermissions(); $this->fileProcessor->dontCheckForUnique = $this->inData['preset']['overwriteExistingFiles'] ? 1 : 0; /** @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication $backendUserAuthentication */ $backendUserAuthentication = $this->getBackendUserAuthentication(); $userTemporaryDirectory = $backendUserAuthentication->getDefaultUploadTemporaryFolder(); $storageUid = $userTemporaryDirectory->getStorage()->getUid(); $file['upload']['1']['target'] = $storageUid . ':' . $userTemporaryDirectory->getIdentifier(); // Checking referer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost != $refInfo['host'] && $this->vC != $this->getBackendUserAuthentication()->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); } else { $this->fileProcessor->start($file); /** @var array<\TYPO3\CMS\Core\Resource\File> $newfile */ $newFiles = $this->fileProcessor->func_upload($file['upload']['1']); } if ($newFiles[0] instanceof File) { return $newFiles[0]; } else { if (!empty($this->fileProcessor->lastError) && GeneralUtility::isFirstPartOfStr($this->fileProcessor->lastError, 'No unique filename')) { /** @var $flashMessage FlashMessage */ $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('f1.tab1.section.importFile.noUniqueFilename'), '', FlashMessage::WARNING); return $flashMessage->render(); } else { return null; } } }
/** * Returns file processing object, initialized only once. * * @return ExtendedFileUtility File processor object */ public function getFileProcObj() { if (!is_object($this->fileProcObj)) { $this->fileProcObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ExtendedFileUtility::class); $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcObj->setActionPermissions(); } return $this->fileProcObj; }
/** * Performing the file admin action: * Initializes the objects, setting permissions, sending data to object. * * @return void */ public function main() { // Initializing: $this->fileProcessor->setActionPermissions(); $this->fileProcessor->setExistingFilesConflictMode($this->overwriteExistingFiles); // Checking referrer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost !== $refInfo['host'] && $this->vC !== $this->getBackendUser()->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $this->fileProcessor->writeLog(0, 2, 1, 'Referrer host "%s" and server host "%s" did not match!', [$refInfo['host'], $httpHost]); } else { $this->fileProcessor->start($this->file); $this->fileData = $this->fileProcessor->processData(); } }
/** * Performing the file admin action: * Initializes the objects, setting permissions, sending data to object. * * @return void */ public function main() { // Initializing: $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcessor->setActionPermissions(); $this->fileProcessor->dontCheckForUnique = $this->overwriteExistingFiles ? 1 : 0; // Checking referrer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost != $refInfo['host'] && $this->vC != $this->getBackendUser()->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'] && $GLOBALS['CLIENT']['BROWSER'] != 'flash') { $this->fileProcessor->writeLog(0, 2, 1, 'Referrer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); } else { $this->fileProcessor->start($this->file); $this->fileData = $this->fileProcessor->processData(); } }
/** * Checks if a file has been uploaded and returns the complete physical fileinfo if so. * * @return string the complete physical file name, including path info. */ public function checkUpload() { $file = GeneralUtility::_GP('file'); $fm = array(); $tempFolder = $this->userTempFolder(); $fm = array($GLOBALS['EXEC_TIME'] => array('path' => $tempFolder, 'name' => array_pop(explode('/', trim($tempFolder, '/'))) . '/')); // Initializing: /* @var $fileProcessor \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility */ $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $this->fileProcessor->init($fm, $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcessor->setActionPermissions(); $this->fileProcessor->dontCheckForUnique = 1; // Checking referer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); } else { $this->fileProcessor->start($file); $newfile = $this->fileProcessor->func_upload($file['upload']['1']); } return $newfile; }
/** * Check if a file has been uploaded * * @throws \InvalidArgumentException * @throws \UnexpectedValueException * @return void */ public function checkUpload() { $file = GeneralUtility::_GP('file'); // Initializing: $this->fileProcessor = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\File\ExtendedFileUtility::class); $this->fileProcessor->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcessor->setActionPermissions(); $this->fileProcessor->setExistingFilesConflictMode((int) GeneralUtility::_GP('overwriteExistingFiles') === 1 ? DuplicationBehavior::REPLACE : DuplicationBehavior::CANCEL); // Checking referer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if ($httpHost != $refInfo['host'] && !$GLOBALS['$TYPO3_CONF_VARS']['SYS']['doNotCheckReferer'] && $this->vC != $this->getBackendUser()->veriCode()) { $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); } else { $this->fileProcessor->start($file); $result = $this->fileProcessor->processData(); if (!empty($result['upload'])) { foreach ($result['upload'] as $uploadedFiles) { $this->uploadedFiles += $uploadedFiles; } } } }
/** * Returns file processing object, initialized only once. * * @return ExtendedFileUtility File processor object */ public function getFileProcObj() { if ($this->fileProcObj === null) { $this->fileProcObj = GeneralUtility::makeInstance(ExtendedFileUtility::class); $this->fileProcObj->setActionPermissions(); } return $this->fileProcObj; }
/** * Returns file processing object, initialized only once. * * @return object File processor object * @todo Define visibility */ public function getFileProcObj() { if ($this->fileProcObj === NULL) { $this->fileProcObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $this->fileProcObj->init(array(), $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcObj->setActionPermissions(); } return $this->fileProcObj; }