# Default Upload Limits for Gravity Forms File Fields

> Gives every Gravity Forms file upload field a safe list of allowed file types and a maximum file size when the field does not set its own.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, uploads, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-default-upload-limits/

## Code

```php
$wpide_gf_upload_ext = 'pdf,doc,docx,jpg,jpeg,png'; // Allowed extensions.
$wpide_gf_upload_mb  = 5;                           // Maximum size per file in MB.

$wpide_gf_upload_defaults = function ( $form ) use ( $wpide_gf_upload_ext, $wpide_gf_upload_mb ) {
    foreach ( $form['fields'] as $field ) {
        if ( 'fileupload' !== $field->type ) {
            continue;
        }
        if ( empty( $field->allowedExtensions ) ) {
            $field->allowedExtensions = $wpide_gf_upload_ext;
        }
        if ( empty( $field->maxFileSize ) ) {
            $field->maxFileSize = $wpide_gf_upload_mb;
        }
    }

    return $form;
};

add_filter( 'gform_pre_render', $wpide_gf_upload_defaults );
add_filter( 'gform_pre_validation', $wpide_gf_upload_defaults );
add_filter( 'gform_pre_submission_filter', $wpide_gf_upload_defaults );
```

## Notes

Values set in the field's own settings always win; the server's upload limit must also allow the size.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Default Upload Limits for Gravity Forms File Fields" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
