Custom upload_dir for Frontend Submission

Support MB Frontend Submission Custom upload_dir for Frontend Submission

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43724
    Matt JMatt J
    Participant

    Hello,

    First, amazing plugin(s)... i've been developing with it for years and its great to see all the new features and functionality.

    I have an interesting situation where logged in users (subscriber) can upload a file using the Frontend Submission extension. I would like those files to be stored in a folder with the id of the post (for archive / backup / organization). The code below works great if you're using the WP dashboard, but if you upload using the Frontend, it just uploads to the "/uploads/application_files/" folder ... eg it does not append the post_id.

    Thoughts about what I might be doing wrong? The code below is based on an earlier support suggestion in the forums.

    thanks 🙂
    matt

    Snippet of code inside my add_filter( 'rwmb_meta_boxes', '...' )

    $post_id = null;
    
    if ( isset( $_GET['post'] ) ) {
        $post_id = intval( $_GET['post'] );
    } elseif ( isset( $_POST['post_ID'] ) ) {
        $post_id = intval( $_POST['post_ID'] );
    } elseif ( isset( $_GET['rwmb_frontend_field_post_id'] ) ) { // Added
        $post_id = intval( $_GET['rwmb_frontend_field_post_id'] ); // Added
    }
    
    ...
    ...
    
    [
        'name'    => 'File',
        'id'      => $prefix.'adjustment_file',
        'type'    => 'file',
        'max_file_uploads' => 1,
        'upload_dir' => WP_CONTENT_DIR . '/uploads/application_files/' . $post_id . '/',
    ],
    #43739
    PeterPeter
    Moderator

    Hello,

    In the frontend, before submitting a post, the post ID is not created so it won't work as your requirement. I think you can create a custom PHP code to check if the file is not located in a post ID folder, then create a post ID folder and move the file there.

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