Beispiel #1
0
 /**
  * Return a path for this file.
  * The file will be copied to this location when it is uploaded. Default behavior stores
  * files to a 'temp' area until the form is actually committed. Descendent forms can override
  * this behavior to move files directly to the final location. E.g. if the file is an image, it
  * needs to be in the document root in order to be displayed in a preview.
  * @param UPLOAD_FILE_FIELD $field
  * @param UPLOADED_FILE $file
  * @param boolean $form_is_valid Will the form be committed?
  * @return string
  * @access private
  */
 protected function _upload_folder_for($field, $file, $form_is_valid)
 {
     $temp_folder = $this->context->upload_options->temp_folder;
     $path = $this->context->resolve_path($temp_folder, Force_root_on);
     return url_to_folder($path);
 }
Beispiel #2
0
 /**
  * Copy the object to the specified folder.
  * If both the source and target albums are {@link Album_location_type_local},
  * and they are different folders, copy the pictures to the new folder.
  * @param ALBUM $folder
  * @param FOLDER_OPERATION_OPTIONS $options
  */
 protected function _copy_to($folder, $options)
 {
     if ($options->update_now) {
         /** @var ALBUM $parent */
         $parent = $this->parent_folder();
         $old_location = $parent->location;
         $old_folder = url_to_folder($parent->picture_folder_url(true));
     }
     parent::_copy_to($folder, $options);
     if ($options->update_now) {
         if ($old_location == Album_location_type_local && $folder->location == Album_location_type_local) {
             $new_folder = url_to_folder($folder->picture_folder_url(true));
             if ($old_folder != $new_folder) {
                 $old_url = new FILE_URL($old_folder);
                 $old_url->replace_name($this->file_name);
                 if ($old_url->extension() == '') {
                     $old_url->replace_extension('jpg');
                 }
                 $new_url = new FILE_URL($new_folder);
                 $new_url->replace_name($this->file_name);
                 if ($new_url->extension() == '') {
                     $new_url->replace_extension('jpg');
                 }
                 if (file_exists($old_url->as_text())) {
                     ensure_path_exists($new_folder);
                     log_message('Copied [' . $old_url->as_text() . '] to [' . $new_url->as_text() . ']', Msg_type_debug_info, Msg_channel_system);
                     if (!copy($old_url->as_text(), $new_url->as_text())) {
                         $this->raise('_copy_to', 'PICTURE', 'Could not copy main image for [' . $this->title_as_plain_text() . '].');
                     }
                 }
                 $old_url->append_to_name(Picture_thumbnail_suffix);
                 $new_url->append_to_name(Picture_thumbnail_suffix);
                 if (file_exists($old_url->as_text())) {
                     ensure_path_exists($new_folder);
                     log_message('Copied [' . $old_url->as_text() . '] to [' . $new_url->as_text() . ']', Msg_type_debug_info, Msg_channel_system);
                     if (!copy($old_url->as_text(), $new_url->as_text())) {
                         $this->raise('_copy_to', 'PICTURE', 'Could not copy thumbnail image for [' . $this->title_as_plain_text() . '].');
                     }
                 }
             }
         }
     }
 }