Opened 16 months ago
Last modified 15 months ago
#63509 new enhancement
Use proper filename for attachment post title
| Reported by: | rilwis | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
In media_handle_upload() function, the file name (and thus, attachment title) is gotten from $_FILES[ $file_id ]['name']. This is the raw/original file name when uploaded. However, developers can change file name after upload by filtering to sanitize_file_name or use unique_filename_callback parameter. This makes the file name (and title) doesn't represent the correct file name after upload.
$name = $_FILES[ $file_id ]['name']; $ext = pathinfo( $name, PATHINFO_EXTENSION ); $name = wp_basename( $name, ".$ext" ); $url = $file['url']; $type = $file['type']; $file = $file['file']; $title = sanitize_text_field( $name );
A simple patch for this is this:
$name = $file['file']; // Get the proper name $ext = pathinfo( $name, PATHINFO_EXTENSION ); $name = wp_basename( $name, ".$ext" );
I tested the patch with classic editor and it works well. However, I haven't figured out for the block editor.
Attachments (1)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch for use proper file name after upload