How to set file type in wp_handle_upload?

I’m using wp_handle_upload to allow users upload .csv files in the front end and it’s working fine. I was wondering how can I limit this to only allow .csv files though since currently it accepts a wide variety of file types. According to the doc this should be possible by overriding the $overrides param but I’m not sure what should I pass it to do so.

Thanks in advance!

2 Answers
2

Got it, looking at the source code I came up with this:

wp_handle_upload($file_input, array('test_form' => false, 'mimes' => array('csv' => 'text/csv')));

To override the mime types just pass mimes as an array wit the key being the file extension and the value as the mime type.

Leave a Comment