Skip Navigation

[Resolved] Control what can be uploaded as files in Forms

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I control a form to allow or disallow certain files types like MP3?

Solution:
You can use the WordPress native

upload_mimes

hook.
https://codex.wordpress.org/Plugin_API/Filter_Reference/upload_mimes

The single types are elaborated on the WordPress DOC as well, you may though profiting checking this too:
https://toolset.com/forums/topic/hi-i-have-a-frontend-form-for-uploading-stl-files-that-is-not-uploading/#post-261584

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 5 replies, has 2 voices.

Last updated by taih 5 years, 6 months ago.

Assisted by: Beda.

Author
Posts
#1290707

I am trying to: Limit the upload from a cred front end form to block mp3s, wavs and ogg.

Link to a page where the issue can be seen: hidden link

I used the below snippet for functions.php found in the support forum, which worked for adding the flac type and limiting the wav, but mp3 can still be uploaded.

function my_custom_mime_types( $mimes ) {

// New allowed mime types.
$mimes['flac'] = 'audio/flac';

// Optional. Remove a mime type.

unset( $mimes['wav'] );
unset( $mimes['mp3'] );
unset( $mimes['m4a'] );
unset( $mimes['ogg'] );

return $mimes;
}

add_filter( 'upload_mimes', 'my_custom_mime_types' );

#1290753

I wish there was a way to filter by file type from within the form itself instead of a functions.php snippet....maybe I missed it and there is, but I did search quite a bit on here.
thanks again, as always - you rock.

#1290867

I think the mime-type is wrong:
https://stackoverflow.com/questions/10688588/which-mime-type-should-i-use-for-mp3
Note that also each browser sends its variation of a mime type for a specific file.

See also Luo's extensive answer here:
https://toolset.com/forums/topic/hi-i-have-a-frontend-form-for-uploading-stl-files-that-is-not-uploading/#post-261584
It seems you'd have to use audio/mpeg

Related to having the feature within the GUI of Toolset Forms, that's a good idea, you can suggest it to our Product Management here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

#1291071

Ive tried using audio/mpeg.
WP doc says: 'mp3|m4a|m4b' => 'audio/mpeg',

As I understand it----- $mimes['mp3'] = 'audio/mpeg'; the first mp3 is the extension and the second audio/mpeg is the type so the unset( $mimes['mp3'] ); is what to use because the mp3 file extension. I have also tried mpeg anyways but without any luck.

I'm just running in circles. I was hoping you'd have a method specific to cred to limit file types in the cred upload function itself...

#1291073

I wanted to put an update on how to solve this if anyone stumbles on the same thing. The mime was right, the problem was with another plugin called "snippets" that wasnt always running it in the front end for whatever reason... I used the built in snippet tool within toolset and it solved the weirdness!

Toolset once again has expanded and allowed me to stop using another plugin!!!!! Love toolset! This suite has paid for itself 10x over! I pretty much run a blank theme and toolset and can accomplish 95% of what I need on any given project! thanks again toolset team!

#1291075

My issue is resolved now. Thank you!