Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 15 years ago

#9233 closed defect (bug) (fixed)

Updating an uploaded media file via AtomPub PUT fails

Reported by: josephscott's profile josephscott Owned by: josephscott's profile josephscott
Milestone: 2.7.2 Priority: normal
Severity: normal Version: 2.7.1
Component: AtomPub Keywords: has-patch
Focuses: Cc:

Description

Tim Armes reported on the wp-xmlrpc email list that attempts to update media uploads via AtomPub PUT are failing:

Finally, I've discovered a more serious problem.  It's not possible to
PUT an updated image file.  Wordpress returns 200 to say that it's all
worked, but in reality it hasn't.  I tracked it down to this code in
the put_file function:

		$location = get_post_meta($entry['ID'], '_wp_attached_file', true);
		$filetype = wp_check_filetype($location);

		if(!isset($location) || 'attachment' != $entry['post_type'] ||
empty($filetype['ext']))
			$this->internal_error(__('Error ocurred while accessing post
metadata for file location.'));

		$fp = fopen("php://input", "rb");
		$localfp = fopen($location, "w+");
log_app("tim", $location);
		while(!feof($fp)) {
			fwrite($localfp,fread($fp, 4096));
		}
		fclose($fp);
		fclose($localfp);

When I PUT to ..../attachement/file/ID the code tries to locate the
physical file and overwrite it.  The problem is that $location
actually gets the path relative to the uploads folder, so it contains
something like 2009/02/myfile.jpg

I've included a patch to fix the location problem by looking up the proper upload dir via wp_upload_dir(). With the patch I've confirmed that updates to an uploaded file via AtomPub PUT work.

I noticed another problem though, it only updates the original file, not the generated versions or the meta data. This is particularly bad if the updated image is a different size. I tried calling wp_generate_attachment_metadata() after updating the image, but it didn't update the generated images or the meta data about the image.

Attachments (1)

wp-app.php.diff (1.2 KB) - added by josephscott 16 years ago.

Download all attachments as: .zip

Change History (7)

#1 follow-up: @josephscott
16 years ago

Updated the diff to correctly call wp_generate_attachment_metadata() so that new generated images are done and meta data gets updated. Kudos to tellyworth for explaining how that worked.

#2 in reply to: ↑ 1 @westi
16 years ago

  • Cc westi added

Replying to josephscott:

Updated the diff to correctly call wp_generate_attachment_metadata() so that new generated images are done and meta data gets updated. Kudos to tellyworth for explaining how that worked.

Is this the correct diff - it doesn't add a call to wp_generate_attachment_metadata()

#3 @josephscott
16 years ago

Oops, must have botched the previous diff update. I've replaced it again and confirmed that it has the corrected wp_generate_attachment_metadata() call in it.

#4 @automattor
16 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10663]) Ensure that updating an uploaded file using AtomPub works correct. Fixes #9233 for trunk props josephscott

#5 @westi
16 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Re open for 2.7.2

#6 @westi
16 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [10664]) Ensure that updating an uploaded file using AtomPub works correct. Fixes #9233 for 2.7.2 props josephscott

Note: See TracTickets for help on using tickets.