The gform_file_path_pre_delete_file filter is executed before an uploaded file (from the File Upload or Post Image fields) is deleted from the entry. It can be used in conjunction with the gform_upload_path filter when changing the location where uploaded files are stored.


The following would apply to all forms.

add_filter( 'gform_file_path_pre_delete_file', 'your_function_name', 10, 2 );


  • $file_path string

    The path of the file to be deleted.

  • $url string

    The url of the file to be deleted.


1. Log the current path

You can use this example when Logging And Debugging to find out what the current path and url are before using the next example to change the path.

add_filter( 'gform_file_path_pre_delete_file', function ( $file_path, $url ) {
    GFCommon::log_debug( 'gform_file_path_pre_delete_file: path of file to be deleted => ' . $file_path );
    GFCommon::log_debug( 'gform_file_path_pre_delete_file: url of file to be deleted => ' . $url );

    return $file_path;
}, 1, 2 );

2. Change the path

This example changes the path of the file to be deleted.

add_filter( 'gform_file_path_pre_delete_file', 'change_file_path', 10, 2 );
function change_file_path( $file_path, $url ) {
   $file_path = '/home/public_html/yourdomainfolder/new/path/filename.pdf';

   return $file_path;


This code should be placed in the functions.php file of your active theme.


This filter was added in Gravity Forms

Source Code

This filter is located in GFFormsModel::delete_physical_file() in forms_model.php.