In Laravel 5 how can I get MIME type from extension? Even better if there's a way to convert array of extensions to array of mimes.
E.g. how to convert array('doc', 'xls')
to array('application/msword', 'application/vnd.ms-excel')
?
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');
$request->file->getMimeType()
$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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With