wasFileUploaded() 공개 메소드

Determines if the file was uploaded or not. If not, will return the appropriate error message.
public wasFileUploaded ( string $field, string $name = null )
$field string The name of the field containing the uploaded file.
$name string The file description string to use in the error message. Default: 'file'.
예제 #1
0
파일: Base.php 프로젝트: horde/horde
 /**
  * Takes all necessary actions for the given import step, parameters and
  * form values and returns the next necessary step.
  *
  * @param integer $action  The current step. One of the IMPORT_* constants.
  * @param array $param     An associative array containing needed
  *                         parameters for the current step.
  *
  * @return mixed  Either the next step as an integer constant or imported
  *                data set after the final step.
  * @throws Horde_Data_Exception
  */
 public function nextStep($action, array $param = array())
 {
     /* First step. */
     if (is_null($action)) {
         return Horde_Data::IMPORT_FILE;
     }
     switch ($action) {
         case Horde_Data::IMPORT_FILE:
             if (!isset($this->_browser)) {
                 throw new LogicException('Missing browser parameter.');
             }
             /* Sanitize uploaded file. */
             try {
                 $this->_browser->wasFileUploaded('import_file', $param['file_types'][$this->_vars->import_format]);
             } catch (Horde_Exception $e) {
                 throw new Horde_Data_Exception($e);
             }
             if ($_FILES['import_file']['size'] <= 0) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("The file contained no data."));
             }
             $this->storage->set('format', $this->_vars->import_format);
             break;
         case Horde_Data::IMPORT_MAPPED:
             if (!$this->_vars->dataKeys || !$this->_vars->appKeys) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("You didn\\'t map any fields from the imported file to the corresponding fields."));
             }
             $dataKeys = explode("\t", $this->_vars->dataKeys);
             $appKeys = explode("\t", $this->_vars->appKeys);
             $dates = $map = array();
             if (!($import_data = $this->storage->get('data'))) {
                 $import_data = array();
             }
             foreach ($appKeys as $key => $app) {
                 $map[$dataKeys[$key]] = $app;
                 if (isset($param['time_fields']) && isset($param['time_fields'][$app])) {
                     $dates[$dataKeys[$key]]['type'] = $param['time_fields'][$app];
                     $dates[$dataKeys[$key]]['values'] = array();
                     $i = 0;
                     /* Build an example array of up to 10 date/time fields. */
                     while ($i < count($import_data) && count($dates[$dataKeys[$key]]['values']) < 10) {
                         if (!empty($import_data[$i][$dataKeys[$key]])) {
                             $dates[$dataKeys[$key]]['values'][] = $import_data[$i][$dataKeys[$key]];
                         }
                         ++$i;
                     }
                 }
             }
             $this->storage->set('map', $map);
             if (count($dates) > 0) {
                 foreach ($dates as $key => $data) {
                     if (count($data['values'])) {
                         $this->storage->set('dates', $dates);
                         return Horde_Data::IMPORT_DATETIME;
                     }
                 }
             }
             return $this->nextStep(Horde_Data::IMPORT_DATA, $param);
         case Horde_Data::IMPORT_DATETIME:
         case Horde_Data::IMPORT_DATA:
             if ($action == Horde_Data::IMPORT_DATETIME) {
                 $params = array('delimiter' => $this->_vars->delimiter, 'format' => $this->_vars->format, 'order' => $this->_vars->order, 'day_delimiter' => $this->_vars->day_delimiter, 'day_format' => $this->_vars->day_format, 'time_delimiter' => $this->_vars->time_delimiter, 'time_format' => $this->_vars->time_format);
             }
             if (!$this->storage->exists('data')) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("The uploaded data was lost since the previous step."));
             }
             /* Build the result data set as an associative array. */
             $data = array();
             $data_map = $this->storage->get('map');
             foreach ($this->storage->get('data') as $row) {
                 $data_row = array();
                 foreach ($row as $key => $val) {
                     if (isset($data_map[$key])) {
                         $mapped_key = $data_map[$key];
                         if ($action == Horde_Data::IMPORT_DATETIME && !empty($val) && isset($param['time_fields']) && isset($param['time_fields'][$mapped_key])) {
                             $val = $this->_mapDate($val, $param['time_fields'][$mapped_key], $params, $key);
                         }
                         $data_row[$mapped_key] = $val;
                     }
                 }
                 $data[] = $data_row;
             }
             return $data;
     }
 }