So, after the new WP updates my form will not allow certain files to upload. I have a Gravity form with an upload field to submit 3D print files. I can get one type of file to work, but not the others. Just hoping someone else has had this issue and has some update on a solution.
I'm using:
add_filter('upload_mimes','add_custom_mime_types',1,1);
function add_custom_mime_types($mime_types){
$mime_types['stl'] = 'application/wavefront-stl';
$mime_types['igs'] = 'application/iges';
$mime_types['stp'] = 'application/step';
$mime_types['step'] = 'application/step';
return $mime_types;
}
Oddly, the .stl will upload but not the others. I have also installed Extra File Types plugin to add file types but no help there. Disable Real MIME Check did not work either.
I also added:
define( 'ALLOW_UNFILTERED_UPLOADS', true );
to wp-config and I can upload these files to the media library as an admin, but I need them to upload from my front-end form.
So, after the new WP updates my form will not allow certain files to upload. I have a Gravity form with an upload field to submit 3D print files. I can get one type of file to work, but not the others. Just hoping someone else has had this issue and has some update on a solution.
I'm using:
add_filter('upload_mimes','add_custom_mime_types',1,1);
function add_custom_mime_types($mime_types){
$mime_types['stl'] = 'application/wavefront-stl';
$mime_types['igs'] = 'application/iges';
$mime_types['stp'] = 'application/step';
$mime_types['step'] = 'application/step';
return $mime_types;
}
Oddly, the .stl will upload but not the others. I have also installed Extra File Types plugin to add file types but no help there. Disable Real MIME Check did not work either.
I also added:
define( 'ALLOW_UNFILTERED_UPLOADS', true );
to wp-config and I can upload these files to the media library as an admin, but I need them to upload from my front-end form.
Thanks to this thread here, I found this code
function fix_wp_csv_mime_bug( $data, $file, $filename, $mimes ) {
$wp_filetype = wp_check_filetype( $filename, $mimes );
$ext = $wp_filetype['ext'];
$type = $wp_filetype['type'];
$proper_filename = $data['proper_filename'];
return compact( 'ext', 'type', 'proper_filename' );
}
add_filter( 'wp_check_filetype_and_ext', 'fix_wp_csv_mime_bug', 10, 4 );
which does allow the files to be uploaded through the form. Not sure what I am opening myself up to, but it works for now.
wp_enqueue_media();
and also initialized the js uploaded`. Note that if you want your users to be able to upload, then you still need to give them the 'upload_files' capability as well. – John Zenith Commented Jan 14, 2019 at 23:55wp_handle_upload_prefilter
filter and see the response you get. – John Zenith Commented Jan 14, 2019 at 23:58wp_handle_upload_prefilter
. – shacker Commented Jan 15, 2019 at 20:21