/** * Moves uploaded files from temporary upload folder to a specified new folder. * This enables you to move the files from a successful submission to another folder and clean the files in temporary upload folder from time to time. * * TypoScript example: * * 1. Set the temporary upload folder * <code> * plugin.Tx_Formhandler.settings.files.tmpUploadFolder = uploads/formhandler/tmp * </code> * * 2. Set the folder to move the files to after submission * <code> * plugin.Tx_Formhandler.settings.finishers.1.class = Tx_Formhandler_Finisher_StoreUploadedFiles * plugin.Tx_Formhandler.settings.finishers.1.config.finishedUploadFolder = uploads/formhandler/finishedFiles/ * plugin.Tx_Formhandler.settings.finishers.1.config.renameScheme = [filename]_[md5]_[time] * </code> * * @return void */ protected function moveUploadedFiles() { $newFolder = $this->settings['finishedUploadFolder']; $newFolder = Tx_Formhandler_StaticFuncs::sanitizePath($newFolder); $uploadPath = Tx_Formhandler_StaticFuncs::getDocumentRoot() . $newFolder; $sessionFiles = Tx_Formhandler_Globals::$session->get('files'); if (is_array($sessionFiles) && !empty($sessionFiles) && strlen($newFolder) > 0) { foreach ($sessionFiles as $field => $files) { $this->gp[$field] = array(); foreach ($files as $key => $file) { if ($file['uploaded_path'] != $uploadPath) { $newFilename = $this->getNewFilename($file['uploaded_name']); Tx_Formhandler_StaticFuncs::debugMessage('copy_file', array($file['uploaded_path'] . $file['uploaded_name'], $uploadPath . $newFilename)); copy($file['uploaded_path'] . $file['uploaded_name'], $uploadPath . $newFilename); t3lib_div::fixPermissions($uploadPath . $newFilename); unlink($file['uploaded_path'] . $file['uploaded_name']); $sessionFiles[$field][$key]['uploaded_path'] = $uploadPath; $sessionFiles[$field][$key]['uploaded_name'] = $newFilename; $sessionFiles[$field][$key]['uploaded_folder'] = $newFolder; $sessionFiles[$field][$key]['uploaded_url'] = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $newFolder . $newFilename; if (!is_array($this->gp[$field])) { $this->gp[$field] = array(); } array_push($this->gp[$field], $newFilename); } } } Tx_Formhandler_Globals::$session->set('files', $sessionFiles); } }
/** * Renders the CSV. * * @return void */ public function process() { $this->pdf = $this->componentManager->getComponent('Tx_Formhandler_Template_TCPDF'); $this->pdf->setHeaderText(Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'headerText')); $this->pdf->setFooterText(Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'footerText')); $this->pdf->AddPage(); $this->pdf->SetFont('Helvetica', '', 12); $view = $this->componentManager->getComponent('Tx_Formhandler_View_PDF'); $this->filename = FALSE; if (intval($this->settings['storeInTempFile']) === 1) { $this->outputPath = t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'); if ($this->settings['customTempOutputPath']) { $this->outputPath .= Tx_Formhandler_StaticFuncs::sanitizePath($this->settings['customTempOutputPath']); } else { $this->outputPath .= '/typo3temp/'; } $this->filename = $this->outputPath . $this->settings['filePrefix'] . Tx_Formhandler_StaticFuncs::generateHash() . '.pdf'; $this->filenameOnly = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'staticFileName'); if (strlen($this->filenameOnly) === 0) { $this->filenameOnly = basename($this->filename); } } $this->formhandlerSettings = Tx_Formhandler_Globals::$settings; $suffix = $this->formhandlerSettings['templateSuffix']; $this->templateCode = Tx_Formhandler_StaticFuncs::readTemplateFile(FALSE, $this->formhandlerSettings); if ($suffix) { $view->setTemplate($this->templateCode, 'PDF' . $suffix); } if (!$view->hasTemplate()) { $view->setTemplate($this->templateCode, 'PDF'); } if (!$view->hasTemplate()) { Tx_Formhandler_StaticFuncs::throwException('no_pdf_template'); } $view->setComponentSettings($this->settings); $content = $view->render($this->gp, array()); $this->pdf->writeHTML($content); $returns = $this->settings['returnFileName']; if ($this->filename !== FALSE) { $this->pdf->Output($this->filename, 'F'); $downloadpath = $this->filename; if ($returns) { return $downloadpath; } $downloadpath = str_replace(t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT'), '', $downloadpath); header('Location: ' . $downloadpath); exit; } else { $this->pdf->Output('formhandler.pdf', 'D'); exit; } }
/** * Searches for upload folder settings in TypoScript setup. * If no settings is found, the default upload folder is set. * * Here is an example: * <code> * plugin.Tx_Formhandler.settings.files.tmpUploadFolder = uploads/formhandler/tmp * </code> * * The default upload folder is: '/uploads/formhandler/tmp/' * * @return void * @static * @author Reinhard Führicht <*****@*****.**> */ public static function getTempUploadFolder() { //set default upload folder $uploadFolder = '/uploads/formhandler/tmp/'; //if temp upload folder set in TypoScript, take that setting $settings = Tx_Formhandler_Globals::$session->get('settings'); if ($settings['files.']['uploadFolder']) { $uploadFolder = Tx_Formhandler_StaticFuncs::getSingle($settings['files.'], 'uploadFolder'); $uploadFolder = Tx_Formhandler_StaticFuncs::sanitizePath($uploadFolder); } //if the set directory doesn't exist, print a message and try to create if (!is_dir(Tx_Formhandler_StaticFuncs::getTYPO3Root() . $uploadFolder)) { Tx_Formhandler_StaticFuncs::debugMessage('folder_doesnt_exist', array(Tx_Formhandler_StaticFuncs::getTYPO3Root() . '/' . $uploadFolder), 2); t3lib_div::mkdir_deep(Tx_Formhandler_StaticFuncs::getTYPO3Root() . '/', $uploadFolder); } return $uploadFolder; }