Ejemplo n.º 1
0
 /**
  * Move the file to the new location.
  * @param string $path
  * @param string $options Can be {@link Uploaded_file_unique_name} or {@link Uploaded_file_overwrite}.
  */
 public function move_to($path, $options = Uploaded_file_unique_name)
 {
     $final_name = $this->normalized_name;
     if ($options == Uploaded_file_unique_name || $this->current_name() != $path . $final_name) {
         if ($options == Uploaded_file_unique_name) {
             while (file_exists($path . $final_name)) {
                 $url = new FILE_URL($final_name);
                 $url->append_to_name('_' . uniqid(rand()));
                 $final_name = $url->as_text();
             }
         }
         ensure_path_exists($path);
         if (!file_exists($path)) {
             $this->raise("Could not create [{$path}] on server.", 'move_to', 'UPLOADED_FILE');
         } else {
             /* If the file has already been moved, use the normal move function to place it in the
                new directory. */
             if (isset($this->_final_name_and_path)) {
                 if ($options == Uploaded_file_overwrite && file_exists($path . $final_name)) {
                     unlink($path . $final_name);
                 }
                 rename($this->_final_name_and_path, $path . $final_name);
                 $this->processed = true;
             } else {
                 if (move_uploaded_file($this->temp_name, $path . $final_name)) {
                     $this->_final_name_and_path = $path . $final_name;
                     $opts = global_file_options();
                     chmod($this->_final_name_and_path, $opts->default_access_mode);
                     $this->processed = true;
                 }
             }
             if (!file_exists($path . $final_name)) {
                 $this->raise("Could not move [" . $this->current_name() . "] to [{$path}{$final_name}]", 'move_to', 'UPLOADED_FILE');
             }
         }
     }
 }
Ejemplo n.º 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() . '].');
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Attempt to create the path to this resource, if it does not exist.
  * Not guaranteed to succeed. Test with {@link exists()} to determine
  * if it succeeded. Will only create the directories; use {@link ensure_exists()}
  * to create the file, if one is included in the URL.
  * @param boolean $normalize_allowed If True, illegal file ids are converted before attempting creation.
  */
 public function ensure_path_exists($normalize_allowed = true)
 {
     if ($normalize_allowed) {
         $this->normalize();
     }
     ensure_path_exists($this->path());
 }
Ejemplo n.º 4
0
 /**
  * Extract the file to the given location.
  * If there is an error in the extraction, it is communicated to the optional 'error_callback'
  * instead of raising an exception (which stops the script).
  * @param string $path
  * @param WEBCORE_CALLBACK $error_callback
  */
 public function extract_to($path, $error_callback = null)
 {
     $url = new FILE_URL($path);
     $url->append($this->normalized_name);
     ensure_path_exists($url->path());
     $this->extracted_name = $url->as_text();
     $this->_extract_to($this->extracted_name, $error_callback);
 }