How to Define a Specific Directory For File Uploads

Overview

Would you like to define a specific directory to store files uploaded through the WPForms File Upload field? With a custom PHP snippet, you can easily define the directory that will hold all of your form uploads.

This tutorial will walk you through the steps to update the default location for file uploads in WPForms.

Setup

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/mysitedomain.com/custom-dir’; or it could be ‘/home/sites/mysitedomain.com/custom-dir’; 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  https://wpforms.com/developers/how-to-define-a-specific-directory-for-file-uploads/
 */

 function wpf_dev_upload_root( $wpforms_upload_root ) {

    //Define a specific directory here
    $wpforms_upload_root = '/home/mysitedomain/public_html/custom-dir';  

    return $wpforms_upload_root;

}

add_filter( 'wpforms_upload_root', 'wpf_dev_upload_root', 10, 1 );

The snippet above will change the default location where file uploads are stored on your site. Keep in mind that it 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