示例#1
0
 /**
  * One of more files for 'field' were uploaded.
  * PHP deletes uploaded files if they are not immediately processed. This means it is possible
  * for a form to successfully upload a file, but not successfully validate. If the upload is not
  * saved, the user will have to upload the file again when resubmitting the form. Forms therefore
  * process each file upload as a separate transaction, so that a form can automatically store
  * successfully uploaded files to a 'temp' directory, where PHP can't delete them. When the form
  * is successfully committed, it can then move the files to their final destinations.
  *
  * The form can determine whether the file needs to be saved by checking the 'form_is_valid' flag
  * to see whether the form itself will be committed or not. If the file was already uploaded in a
  * previous form submission attempt, the file will be marked as 'processed'.
  *
  * @see CONTEXT::$upload_options
  * @see _move_uploaded_file()
  *
  * @param UPLOAD_FILE_FIELD $field
  * @param UPLOADED_FILE $file
  * @param boolean $form_is_valid Will the form be committed?
  * @access private
  */
 protected function _process_uploaded_file($field, $file, $form_is_valid)
 {
     if (!$file->processed && $file->is_valid()) {
         $f = $this->_upload_folder_for($field, $file, $form_is_valid);
         if ($f) {
             $this->_move_uploaded_file($field, $file, $f, $form_is_valid);
             if (!file_name_to_url($file->current_name())) {
                 $this->record_error($field->id, 'Error in upload configuration (uploaded file [' . $file->current_name() . '] is not visible under any registered mapping).');
             }
         }
     }
 }
 /**
  * Store the form's values to this picture.
  * @param PICTURE $obj
  * @access private
  */
 protected function _store_to_object($obj)
 {
     parent::_store_to_object($obj);
     $file_name = $this->_selected_file_name();
     if ($this->value_for('use_upload')) {
         $file_name = $this->context->resolve_file(file_name_to_url($file_name), Force_root_on);
     }
     $obj->file_name = $file_name;
     if (isset($this->_exif_date)) {
         $obj->date = $this->_exif_date;
     }
 }
示例#3
0
 /**
  * Fully resolved URL to the thumbnail.
  * May be empty.
  * @see thumbnail_file_name()
  * @return string
  */
 public function thumbnail_url()
 {
     $thumb_url = $this->thumbnail_file_name();
     if (file_exists($thumb_url)) {
         return file_name_to_url($thumb_url);
     }
     return '';
 }
示例#4
0
 /**
  * Load image properties form the given file.
  * @param string $name Full path to the file to load. May be a URL or local file.
  * @param boolean $include_exif Load EXIF digital camera information from the file?
  */
 public function load_from_file($name, $include_exif)
 {
     $this->php_type = null;
     if (is_file($name)) {
         $name = ensure_has_full_path($name);
         $this->file_name = $name;
         $this->url = file_name_to_url($name);
     } else {
         $this->url = $name;
         $name_as_file = url_to_file_name($name);
         if ($name_as_file) {
             /* File is local. Only attempt loading if it exists (this avoids trying to
              * load through a loopback URL because the file isn't on the server).
              */
             if (@is_file($name_as_file)) {
                 $name = $name_as_file;
                 $this->file_name = $name_as_file;
             } else {
                 $name = '';
                 $this->file_name = null;
             }
         } else {
             $name = str_replace(' ', '%20', $name);
         }
     }
     if ($name) {
         if ($include_exif) {
             $this->_read_exif($name);
             if (!$this->php_type) {
                 $this->_read_image_info($name);
             }
         } else {
             $this->_read_image_info($name);
         }
         if (!$this->exists()) {
             $this->file_name = null;
         }
     }
 }