Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#14627 closed defect (bug) (fixed)

wp_handle_upload unique_filename_callback problem

Reported by: xiosen's profile xiosen Owned by: nacin's profile nacin
Milestone: 3.1 Priority: normal
Severity: major Version: 3.0.1
Component: Upload Keywords: has-patch
Focuses: Cc:

Description

Right now I am using wp_handle_upload to upload a file and I would like to provide a custom filename using the unique_filename_callback parameter.

If you look at 3.0.1 wp-includes/functions.php line 2218 inside the wp_unique_filename function. You will see that $dir, $name are passed into the callback function. However, the $name parameter is the filename without the extension, so the only thing missing is $ext. A callback function is unable to generate a proper filename without the original ext the file is in.

Line 2218 needs to look like:
$filename = $unique_filename_callback( $dir, $name, $ext );

Attachments (1)

14627.diff (1.5 KB) - added by nacin 15 years ago.

Download all attachments as: .zip

Change History (6)

#1 @mikeschinkel
15 years ago

I just found the exact same thing! Line 2218 in v3.0.1 of /wp-includes/functions.php has the following code:

$filename = $unique_filename_callback( $dir, $name );

This is all that would be needed to "fix" this problem:

$filename = $unique_filename_callback( $dir, $name, $ext );

Adding a third parameter would enable a developer to return a working file.

As it, the 'unique_filename_callback' is pretty much unusable. This is teeny, tiny fix, please accept for v3.1.

-Mike

#2 @nacinLead Developer
15 years ago

  • Milestone changed from Awaiting Review to 3.1
  • Owner set to nacin
  • Status changed from new to accepted

Seems sane. We should probably also use call_user_func.

@nacinLead Developer
15 years ago

#3 @nacinLead Developer
15 years ago

  • Keywords has-patch added; needs-patch removed

Someone want to test this?

#4 @nacinLead Developer
15 years ago

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

(In [16025]) Use call_user_func for wpnique_filename callback. fixes #14627.

#5 @aaroncampbellCore Committer
15 years ago

Sorry, it looks like I uploaded a partial diff to #12824 and it only partially fixed the issue.

As for the patch, I tested it quickly and it works fine in my case. However, my problem had nothing to do with needing an extension. I just needed to be able to use a method in a class rather than a function.

Note: See TracTickets for help on using tickets.