How to Define a Specific Directory For File Uploads


Would you like to define a specific directory to store your file uploads that are uploaded through the WPForms File Upload form field? With a small PHP snippet, you can easily define this directory that will hold all of your form uploads and we’ll walk you through each step.


To define your directory, you’ll need to copy this snippet to your site. You’ll need to know the server path of where you want to store these. These can be different depending on how the site is set up.

For example your root path could be ‘/home/’; or it could be ‘/home/sites/’; or even ‘/home/mysitedomain/public_html/custom-dir’;. If you’re unsure what your root path would be, check with your hosting provider.

 * Define a specific directory for files uploaded through the File Upload addon.
 * @link

 function wpf_dev_upload_root( $wpforms_upload_root ) {

    //Define a specific directory here
    $wpforms_upload_root = '/home/mysitedomain/public_html/custom-dir';  
    return $path;
add_filter( 'wpforms_upload_root', 'wpf_dev_upload_root', 10, 1 );

This change will change the location of where the files are stored. This will not update the email notification URL.

And that’s all you need to define a specific directory for the File Upload field. When files are uploaded through your forms, they will be stored in the custom-dir folder on your server.

Would you like to alter the timeout function on the Modern Upload Field? Check out our snippet on How to Change the Timeout on the Modern File Upload.

Filter Reference: wpforms_upload_root