/**
  * The main method called by the controller
  *
  * @param array $gp The GET/POST parameters
  * @param array $settings The defined TypoScript settings for the finisher
  * @return array The probably modified GET/POST parameters
  */
 public function process()
 {
     $this->olderThanValue = $this->settings['clearTempFilesOlderThan.']['value'];
     $this->olderThanUnit = $this->settings['clearTempFilesOlderThan.']['unit'];
     if (!empty($this->olderThanValue) && is_numeric($this->olderThanValue)) {
         $uploadFolder = Tx_Formhandler_StaticFuncs::getTempUploadFolder();
         $this->clearTempFiles($uploadFolder, $this->olderThanValue, $this->olderThanValue);
     }
     return $this->gp;
 }
コード例 #2
0
 /**
  * Processes uploaded files, moves them to a temporary upload folder, renames them if they already exist and
  * stores the information in user session
  *
  *
  * @return void
  * @author	Reinhard Führicht <*****@*****.**>
  */
 protected function processFiles()
 {
     $sessionFiles = Tx_Formhandler_Globals::$session->get('files');
     $tempFiles = $sessionFiles;
     //if files were uploaded
     if (isset($_FILES) && is_array($_FILES) && !empty($_FILES)) {
         //get upload folder
         $uploadFolder = Tx_Formhandler_StaticFuncs::getTempUploadFolder();
         //build absolute path to upload folder
         $uploadPath = Tx_Formhandler_StaticFuncs::getTYPO3Root() . $uploadFolder;
         if (!file_exists($uploadPath)) {
             Tx_Formhandler_StaticFuncs::debugMessage('folder_doesnt_exist', array($uploadPath), 3);
             return;
         }
         //for all file properties
         foreach ($_FILES as $sthg => $files) {
             //if a file was uploaded
             if (isset($files['name']) && is_array($files['name'])) {
                 //for all file names
                 foreach ($files['name'] as $field => $name) {
                     if (!isset($this->errors[$field])) {
                         $exists = FALSE;
                         if (is_array($sessionFiles[$field])) {
                             foreach ($sessionFiles[$field] as $idx => $fileOptions) {
                                 if ($fileOptions['name'] === $name) {
                                     $exists = TRUE;
                                 }
                             }
                         }
                         if (!$exists) {
                             $filename = substr($name, 0, strpos($name, '.'));
                             if (strlen($filename) > 0) {
                                 $ext = substr($name, strpos($name, '.'));
                                 $suffix = 1;
                                 $filename = str_replace(' ', '_', $filename);
                                 //build file name
                                 $uploadedFileName = $filename . $ext;
                                 //rename if exists
                                 while (file_exists($uploadPath . $uploadedFileName)) {
                                     $uploadedFileName = $filename . '_' . $suffix . $ext;
                                     $suffix++;
                                 }
                                 $files['name'][$field] = $uploadedFileName;
                                 //move from temp folder to temp upload folder
                                 move_uploaded_file($files['tmp_name'][$field], $uploadPath . $uploadedFileName);
                                 t3lib_div::fixPermissions($uploadPath . $uploadedFileName);
                                 $files['uploaded_name'][$field] = $uploadedFileName;
                                 //set values for session
                                 $tmp['name'] = $name;
                                 $tmp['uploaded_name'] = $uploadedFileName;
                                 $tmp['uploaded_path'] = $uploadPath;
                                 $tmp['uploaded_folder'] = $uploadFolder;
                                 $uploadedUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $uploadFolder . $uploadedFileName;
                                 $uploadedUrl = str_replace('//', '/', $uploadedUrl);
                                 $tmp['uploaded_url'] = $uploadedUrl;
                                 $tmp['size'] = $files['size'][$field];
                                 $tmp['type'] = $files['type'][$field];
                                 if (!is_array($tempFiles[$field]) && strlen($field) > 0) {
                                     $tempFiles[$field] = array();
                                 }
                                 array_push($tempFiles[$field], $tmp);
                                 if (!is_array($this->gp[$field])) {
                                     $this->gp[$field] = array();
                                 }
                                 array_push($this->gp[$field], $uploadedFileName);
                             }
                         }
                     }
                 }
             }
         }
     }
     Tx_Formhandler_Globals::$session->set('files', $tempFiles);
     Tx_Formhandler_StaticFuncs::debugMessage('Files:', array(), 1, (array) $tempFiles);
 }