I have a front end form with file upload that limits files to certain types. I need to display an error message if a user submits a file in an unsupported format.
File upload works correctly and I can limit uploads to certain types using the below function. I've added this function to the theme functions.php.
// limit front end upload to image formats only
add_filter('upload_mimes', 'image_upload_mimes');
function image_upload_mimes ( $existing_mimes=array() ) {
// remove all mime types
unset($existing_mimes);
$existing_mimes = array('jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
'tif|tiff' => 'image/tiff');
// and return the new list of mimes
return $existing_mimes;
}
If the user submits an unsupported format, I would like to display an error message indicating that the format is not supported. I believe that the back end has a built in feature for this.
How do I detect that an uploaded format is unsupported from the front end?