• Hello,

    Is it possible to determine to which folder the file should be uploaded before uploading the document via media upload? Or is there a way to change the folder to save the document based on the document type?

    Thanks,
    Jan

    • This topic was modified 3 years, 4 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    This hook allows you to change the uploads folder “on the fly”: https://developer.www.ads-software.com/reference/hooks/upload_dir/

    Moderator bcworkz

    (@bcworkz)

    Altering the upload directory on the fly must be done very carefully or it’ll cause issues with other code whose files rightly reside in /uploads/. The filter callback is not passed useful information regarding document type.

    I’d take a different approach, using ‘pre_move_uploaded_file’ filter to override the default move destination from the temp folder to its final location. Your callback is then passed useful document information. Review the source code for guidance on using this filter. You may want to largely mimic what WP does to move the file by default (currently starting at line 928)

    You must then also use the ‘wp_handle_upload’ filter to alter the data passed back to calling functions so the related attachment post will have correct path data.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Changes to the media storage folder’ is closed to new replies.