Using Gravity Forms ‘gform_file_permission’ PHP filter

The gform_file_permission filter is executed when uploading a file. It can be used to change the default permissions of uploaded files.

Usage

add_filter('gform_file_permission', 'set_file_permission', 10, 2);

Parameters

  • $permission (string): The file permission to be filtered (i.e. 0755).
  • $path (string): The full file path.

More information

See Gravity Forms Docs: gform_file_permission

Examples

Change permissions of uploaded files to 0755

This example changes the permissions of uploaded files to 0755.

add_filter('gform_file_permission', 'set_file_permission', 10, 2);

function set_file_permission($permission, $path) {
    // Note the octal value with the leading zero. Don't return a string.
    return 0755;
}

Make uploaded files read-only

This example makes uploaded files read-only.

add_filter('gform_file_permission', 'set_read_only_permission', 10, 2);

function set_read_only_permission($permission, $path) {
    return 0444;
}

Set uploaded files to full permissions

This example sets uploaded files to full permissions.

add_filter('gform_file_permission', 'set_full_permissions', 10, 2);

function set_full_permissions($permission, $path) {
    return 0777;
}

Set uploaded files to group read and execute permissions

This example sets uploaded files to group read and execute permissions.

add_filter('gform_file_permission', 'set_group_read_execute_permissions', 10, 2);

function set_group_read_execute_permissions($permission, $path) {
    return 0750;
}

Set uploaded files to group and user read, write, and execute permissions

This example sets uploaded files to group and user read, write, and execute permissions.

add_filter('gform_file_permission', 'set_user_group_permissions', 10, 2);

function set_user_group_permissions($permission, $path) {
    return 0770;
}