File Upload Folder

Est. Reading: 2 minutes
By: FDM Digital
Created: 12/20/2016
Category:
Difficulty: Intermediate

File Upload Folder

×Warning: This tutorial was created 2923 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

Hi All,

I came across a problem in the last few days and i thought i'd share the solution with you all.

The Problem:

I wanted to change the folder that files will be uploaded to when using the File Upload field to an existing folder somewhere else on my server and NOT as a sub-directory of the /uploads/Formidable/ folder. To further complicate matters i already have a folder per client set up (actually created by the WP-Client Plugin) and i need the folder name to be looked up depending on who is logged in although you could remove this addition if you don't need it.

The Solution:

The solution is actually quite simple although it took me 2 days to get there as i'm not a coder by any sense. Add this to a new plugin or your themes functions.php file.

add_filter( 'frm_upload_folder', 'frm_custom_upload', 10, 2 );
    function frm_custom_upload( $folder, $atts ) {
    if ( $atts['form_id'] == 92 ) { // change to your form id
    global $current_user;
    $folder = '../uploads/wpclient/_file_sharing/' . $current_user->wpc_cf_client_file_cat;
 }
    return $folder;
}

The folder file path requires ../ at the start to take you up a level from the default Formidable folder and then from there you can define the folder you wish your files to be uploaded to.

I have a custom field in each user profile which contains the name of the users File Upload folder which is then looked up and added to the end of the file path using $current_user->wpc_cf_client_file_cat

So now when my client Mr Test logs in and uploads a file using this form it will be uploaded to his existing folder like this:

/public_html/wp-content/uploads/wpclient/_file_sharing/MrTest instead of the normal Formidable directory.

Hope that helps.

Leave a Reply

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crosschevron-leftchevron-rightarrow-right