We need to made few tweaks in code to make sure it is working fine.
add_action( 'forminator_custom_form_submit_before_save_entry', 'handle_forminator_file_upload', 10, 3 );
function handle_forminator_file_upload( $entry, $form_id, $field_data_array ) {
$target_form_id = 306; // Here we need to ensure that 306 is the correct form ID.
if ( $form_id == $target_form_id ) {
// Here we are looping through the field data array to find the file upload field.
foreach ( $field_data_array as $field ) {
// Here we are checking if the field type is 'file'.
if ( 'file' === $field['type'] && ! empty( $field['value']['file'] ) ) {
// Here we are retrieving the file data.
$file_data = $field['value']['file'];
// Here we are getting the uploaded file's path.
$file_path = $file_data['file_path'];
// This is to check if the file exists before attempting to read it.
if ( file_exists( $file_path ) ) {
$file_content = file_get_contents( $file_path );
// This is to log the file content for debugging.
error_log( 'File content: ' . $file_content );
} else {
error_log( 'File does not exist at path: ' . $file_path );
}
}
}
}
}