Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/11e031b6b7b8776511c6deeda3e54058 to your computer and use it in GitHub Desktop.
Save spivurno/11e031b6b7b8776511c6deeda3e54058 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Get Uploaded Files Prior to Submission
<?php
/**
* Gravity Wiz // Gravity Forms // Get Uploaded Files Prior to Submission
*
* @param integer $form_id The form ID that contains that field for which you are fetching the uploaded file details.
* @param GF_Field $field The field object for which you are fetching the uploaded file details.
*
* @return array|bool
*/
function gw_get_uploaded_file_deets( $form_id, $field ) {
$input_name = sprintf( 'input_%s', $field->id );
$is_save_and_continue = rgget( 'gf_token' ) != false;
// hack alert: force retrieval of unique ID for filenames when continuing from saved entry
if( $is_save_and_continue && ! isset( $_POST['gform_submit'] ) ) {
$is_gform_submit_set_manually = true;
$_POST['gform_submit'] = $form_id;
}
$uploaded_files = isset( GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] ) ? GFFormsModel::$uploaded_files[ $form_id ][ $input_name ] : array();
$file_info = rgar( $field, 'multipleFiles' ) ? $uploaded_files : GFFormsModel::get_temp_filename( $form_id, $input_name );
if( $is_save_and_continue && ! isset( $_POST['gform_submit'] ) ) {
$_POST['gform_submit'] = $form_id;
}
// hack alert: force retrieval of unique ID for filenames when continuing from saved entry
if( isset( $is_gform_submit_set_manually ) ) {
unset( $_POST['gform_submit'] );
}
return $file_info;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment