• screamapillar

    (@screamapillar)


    I’m trying to rename image files:

    • upon upload
    • to a specific post type
    • using that post’s custom fields.

    I’m creating a custom field contains the IDs of multiple uploaded images. The interface for adding them uses this method for invoking the media uploader.

    In the plugin I’m making, it’s critical to rename the uploaded image files. This post type has another custom field called “Reference ID”, which is unique and is not the post ID. This reference number must prefix the image filename.

    I have tried adding filters to wp_handle_upload_prefilter and sanitize_file_name, but the problem is that I cannot get post information to these functions. If this is possible, that would probably solve the problem.

    The only other alternative I see is to create my own upload interface and use wp_insert_attachment which will easily allow me to rename files based on post meta. I’d rather stick to WP’s own media uploader but it’s looking like that may not be possible.

    I’m sure there must be some alternative I haven’t thought of. Input and ideas of any kind are much appreciated.

    Many thanks to those who respond.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I think you need to simply keep track of the uploads as they happen, letting the filenames be as they may for now. Perhaps start a transient array keyed by post ID to keep track of uploads.

    Then when the post type is actually saved, go back and rename the uploaded files as needed based on the now available $_POST data.

Viewing 1 replies (of 1 total)
  • The topic ‘Rename files based on post meta upon upload’ is closed to new replies.