Custom upload file name
- This topic has 7 replies, 3 voices, and was last updated 3 years, 11 months ago by
sherwin_flight.
-
AuthorPosts
-
April 24, 2021 at 12:25 AM #27579
sherwin_flight
ParticipantHello,
I'm using a "File" field to upload files to a custom folder. I'm wondering if there's any way to change the name of the file that's uploaded?
Right now I have a separate metabox for file uploads, that I created myself. Everything else has been created using the Metabox plugin. If I can figure out how to rename the uploaded files I could get rid of my custom metabox and just use th plugin.
April 24, 2021 at 6:13 PM #27601Long Nguyen
ModeratorHi,
There are some plugins that help you to rename the file uploaded. Please try this one https://wordpress.org/plugins/media-file-renamer/
April 25, 2021 at 1:43 AM #27616sherwin_flight
ParticipantI have some custom code I use for that right now, just wasn't sure how it would work with your plugin.
The upload script we're using now has a callback for a custom upload folder, which your plugin also has, and a callback for a custom file name, which the Meta Box plugin doesn't have. We upload several types of files, and they're named differently depending on the document type.
$unit_inspection_documentation_upload_overrides = array( 'test_form' => false, 'unique_filename_callback' => 'unit_inspection_documentation_filename' ); $unit_inspection_documentation_uploaded_file = wp_handle_upload($_FILES['unit_inspection_documentation_attachment'], $unit_inspection_documentation_upload_overrides);
So in our current code it calls a "unique_filename_callback" function to get the name of the file before passing it to wp_handle_upload. That function names the file based on values from the database. That all works as expected.
However, I've been migrating our custom post metaboxes over to your plugin, and these uploads are the only part I can't figure out.
It's not a huge problem, because if I can't figure it out I'll just use a second custom metabox with our own code for the file uploads, and use Meta Box for the rest. Was just hoping to combine them into one tabbed Meta Box.
Right now I'm not sure how to integrate a custom filename function
April 26, 2021 at 9:32 AM #27637Long Nguyen
ModeratorHi,
Thank you for your feedback.
I will inform the development team to support this option in future updates.
May 4, 2021 at 10:57 PM #27908sherwin_flight
ParticipantThanks! That's the only option that's missing from using Metabox for all of my custom metaboxes.
May 6, 2021 at 9:52 AM #27954Anh Tran
KeymasterHi, it's just added to Meta Box and will be available in the next version.
May 30, 2021 at 1:16 PM #28519sherwin_flight
ParticipantI saw this was recently added. Thank you very much for this feature and great support.
May 31, 2021 at 1:49 AM #28536sherwin_flight
ParticipantI tried this amd it works. But the file name displayed in the meta box isn't encoded properly.
In the folder the file name has spaces in it which we want. But when the attached file is shown in the Meta Box the encoding has %20 instead of spaces.
-
AuthorPosts
- You must be logged in to reply to this topic.