I'm trying to upload an mp3 file with laravel. And when I do
dd(Input::file('mp3')->guessExtension());
It gives me back "bin" in a string with certain mp3 files. With other files this is correct, and it is giving me back 'mpga'. What does this "bin" as extension mean?
This file doesn't go through my validation now when I do this rule :
$validator = Validator::make($request->all(), [
'mp3' => 'required|mimes:mpga|max:500',
]);
When I dump my request it says that the mimetype is mpga , but still it comes back with an error: 'file must be of type mpga'
To answer one of your questions, 'bin' is returned for octet streams:
// Part of the MimeTypeExtensionGuesser class
'application/octet-stream' => 'bin',
Laravel uses Symfony File and Symfony File uses built-in PHP's finfo to guess the mime type.
Therefore, your question becomes – why finfo detects some of your MP3 files as application/octet-stream? There is a possibility that something is slightly wrong about this specific MP3 file, given that other files pass.
By the way, try in a shell:
$ file -I file.mp3
file.mp3: audio/mpeg; charset=binary
See if you get correct response.
You can debug your files using services like
http://mime.ritey.com/
and check if there is any error in validator
if ($validator -> passes()) {
// passes
} else {
dd($validator->errors()->all());
}
If validator is not working as you expect you can try using another validator like http://pastebin.com/raw/NcL5BLwg
Read here: File upload mime-type validation with Laravel 4
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