[wp-trac] [WordPress Trac] #9233: Updating an uploaded media file via AtomPub PUT fails

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 26 03:27:04 GMT 2009


#9233: Updating an uploaded media file via AtomPub PUT fails
--------------------------+-------------------------------------------------
 Reporter:  josephscott   |       Owner:  josephscott
     Type:  defect (bug)  |      Status:  new        
 Priority:  normal        |   Milestone:  2.7.2      
Component:  AtomPub       |     Version:  2.7.1      
 Severity:  normal        |    Keywords:  has-patch  
--------------------------+-------------------------------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9233>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list