Hey, something like this should do the trick.
add_filter( 'itsg_gf_ajaxupload_filename', 'my_itsg_gf_ajaxupload_filename', 10, 7 );
function my_itsg_gf_ajaxupload_filename( $name, $file_path, $size, $type, $error, $index, $content_range ) {
$form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : null; // get the form_id out of the post
$field_id = isset( $_POST['field_id'] ) ? $_POST['field_id'] : null; // get the field_id out of the post
$file_extension = pathinfo( $name, PATHINFO_EXTENSION ); // get the file type out of the URL
$form_meta = GFFormsModel::get_form_meta( $form_id ); // load the form meta
$field = GFFormsModel::get_field( $form_meta, $field_id ); // get the field
$field_label = GFFormsModel::get_label( $field ); // get the field label
$field_label = preg_replace( '/[^A-Za-z0-9 ]/', '', $field_label ); // make sure the field label only includes supported characters -- restricting to A-Z 0-9
$name = $field_label . '_' . $form_id . '_' . $field_id . '.' . $file_extension; // put it together
return $name; // now return the new name
}
No need to worry about duplicate file names being uploaded to the same folder, the plugin will add a number to the file if it already exists.
-
This reply was modified 8 years, 3 months ago by
ovann86.