public function load_from_request()
 {
     $this->upload_max_filesize = text_to_file_size(ini_get('upload_max_filesize'));
     $this->post_max_size = text_to_file_size(ini_get('post_max_size'));
     $this->ini_max_file_size = min($this->upload_max_filesize, $this->post_max_size);
     $this->max_file_size = $this->ini_max_file_size;
     $this->form_max_file_size = read_var(Form_max_file_size_field_name, 0);
     if ($this->form_max_file_size && $this->form_max_file_size < $this->max_file_size) {
         $this->max_file_size = $this->form_max_file_size;
     }
     $this->_file_sets = array();
     $this->total_files = 0;
     foreach ($_FILES as $file_set_id => $file_info) {
         $file_set = new UPLOADED_FILE_SET($this, $file_set_id);
         if ($file_set->size()) {
             $this->total_files += $file_set->size();
             $this->file_sets[$file_set_id] = $file_set;
         }
     }
     /*
         In order to smoothly support uploading with form validation, we allow a form to process
         a previously uploaded file and store its properties in the form. The uploader reads those
         values and 'pretends' that this is a valid PHP upload file. This way, form validation can
         occur over multiple submissions but a successfully uploaded file need only be uploaded once.
     */
     $uploads = read_var($this->stored_info_name);
     if (is_array($uploads)) {
         for ($idx = sizeof($uploads) - 1; $idx >= 0; $idx--) {
             $upload = $uploads[$idx];
             $file = new UPLOADED_FILE($this, '', 0, '', '', 0);
             $file_set_id = $file->load_from_text($upload);
             if (isset($this->file_sets[$file_set_id])) {
                 $file_set = $this->file_sets[$file_set_id];
             } else {
                 $file_set = new UPLOADED_FILE_SET($this, $file_set_id);
                 $this->file_sets[$file_set_id] = $file_set;
             }
             array_unshift($file_set->files, $file);
         }
     }
 }
Exemple #2
0
 /**
  * Performs the actual move for {@link _process_uploaded_file()}.
  * Can be called from {@link _prepare_for_commit()} in descendent forms to use
  * the same mechanisms for resolved overwrite options.
  * @param UPLOAD_FILE_FIELD $field File is associated with this field.
  * @param UPLOADED_FILE $file Move this file object.
  * @param string $path Move to this folder.
  * @param boolean $form_is_valid Will the form be committed?
  * @access private
  */
 protected function _move_uploaded_file($field, $file, $path, $form_is_valid = true)
 {
     $file->move_to($path, $this->_upload_file_copy_mode($field, $file, $form_is_valid));
 }