[wp-trac] [WordPress Trac] #21679: media_handle_upload does not provide a way to change the file's name

WordPress Trac noreply at wordpress.org
Tue Aug 6 02:27:40 UTC 2013


#21679: media_handle_upload does not provide a way to change the file's name
-------------------------------------------------+-------------------------
 Reporter:  Willshouse                           |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Media                                |  Review
 Severity:  normal                               |     Version:  2.5
 Keywords:  has-patch needs-testing dev-         |  Resolution:
  feedback                                       |
-------------------------------------------------+-------------------------

Comment (by jsdavis02):

 I just fixed this on an install of mine. Wilishouse did the same thing I
 initially did assuming we got back the actual file object instead of a
 modified associative array from file.php...

 return apply_filters( 'wp_handle_upload', array( 'file' => $new_file,
 'url' => $url, 'type' => $type ), 'upload' );

 So to still avoid changing two core files I just did a quick change to
 media.php to strip it from the full upload path, so it has a filename that
 ran through all sanitizing and filter calls.
 {{{
  //$name = $_FILES[$file_id]['name'];  --wrong time to pull and wrong
 place to pull from,
  //allow handle upload and prefilter to run first
         $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
         $name = substr($file['file'],strrpos($file['file'],'/')+1);
 }}}

 It really should not be difficult to add this in and it should be pretty
 low impact

--
Ticket URL: <http://core.trac.wordpress.org/ticket/21679#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list