Laravel 5 - get MIME type from file extension
When "guzzlehttp/guzzle": "~5.3|~6.0" is in your composer.json, you can use this:
$mimetype = \GuzzleHttp\Psr7\mimetype_from_filename('foo.doc');
$mimetype = \GuzzleHttp\Psr7\mimetype_from_extension('doc');
Simply the best in L5:
\File::mimeType('physical/path/to/file.ext');
to get file mimetype
$request->file->getMimeType()
validation code
$request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg'
'mp3'=>'required|mimetypes:audio/mpeg'
]);
you can get the file type from above code, after that you can set that to mimetypes like set for mp3