Custom upload file name

Support General Custom upload file nameResolved

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #27579
    sherwin_flightsherwin_flight
    Participant

    Hello,

    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.

    #27601
    Long NguyenLong Nguyen
    Moderator

    Hi,

    There are some plugins that help you to rename the file uploaded. Please try this one https://wordpress.org/plugins/media-file-renamer/

    #27616
    sherwin_flightsherwin_flight
    Participant

    I 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

    #27637
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for your feedback.

    I will inform the development team to support this option in future updates.

    #27908
    sherwin_flightsherwin_flight
    Participant

    Thanks! That's the only option that's missing from using Metabox for all of my custom metaboxes.

    #27954
    Anh TranAnh Tran
    Keymaster

    Hi, it's just added to Meta Box and will be available in the next version.

    #28519
    sherwin_flightsherwin_flight
    Participant

    I saw this was recently added. Thank you very much for this feature and great support.

    #28536
    sherwin_flightsherwin_flight
    Participant

    I 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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.