-
-
Save richardW8k/17d8ee4285d1c0c82125262b9b4348ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'gform_pre_process_178', function ( $form ) { | |
GFCommon::log_debug( 'gform_pre_process: running' ); | |
$base64_string = rgpost( 'input_3' ); | |
if ( ! empty( $base64_string ) ) { | |
GFCommon::log_debug( 'gform_pre_process: found string' ); | |
$target_dir = GFFormsModel::get_upload_path( $form['id'] ) . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; | |
if ( ! is_dir( $target_dir ) ) { | |
GFCommon::log_debug( 'gform_pre_process: creating tmp folder' ); | |
if ( ! wp_mkdir_p( $target_dir ) ) { | |
GFCommon::log_debug( "gform_pre_process: Couldn't create the tmp folder: " . $target_dir ); | |
return; | |
} else { | |
GFCommon::recursive_add_index_file( $target_dir ); | |
} | |
} | |
$upload_field_id = 4; | |
$file_extension = 'png'; | |
$file_contents = base64_decode( preg_replace( '#^data:image/\w+;base64,#i', '', $base64_string ) ); | |
$temp_filename = sprintf( '%s_input_%s.%s', GFFormsModel::get_form_unique_id( $form['id'] ), $upload_field_id, $file_extension ); | |
$result = file_put_contents( $target_dir . $temp_filename, $file_contents ); | |
GFCommon::log_debug( 'gform_pre_process: file_put_contents result: ' . var_export( $result, true ) ); | |
$uploaded_file_name = 'testing.png'; | |
$_POST['gform_uploaded_files'] = json_encode( array( 'input_' . $upload_field_id => $uploaded_file_name ) ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment