functions - Wordpress upload_mimes not working for front-end uploads of 3D files

admin2025-06-04  3

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.

Share Improve this question asked Jan 14, 2019 at 23:28 shackershacker 236 bronze badges 3
  • Have you included the media library scripts on the front-end 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:55
  • furthermore, if the upload is still not working on the front-end, try inspecting the wp_handle_upload_prefilter filter and see the response you get. – John Zenith Commented Jan 14, 2019 at 23:58
  • I'm using Gravity Forms plugin to handle the file uploads. Is this something that should already be present in their code? Not quite sure how to see the response from the wp_handle_upload_prefilter. – shacker Commented Jan 15, 2019 at 20:21
Add a comment  | 

1 Answer 1

Reset to default 1

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749007567a315567.html

最新回复(0)