Checking Laravel MIME

I ran into a problem related to checking the loading of JavaScript files using Laravel, where the validation rule is:

'javascript_file' => 'required|mimes:js'

Which should work, as far as I know, since Laravel uses mime_content_type () to guess file memes, but go wrong, giving me a mime type error when testing with a application/javascriptmime type file

Edit: dd($_FILES)gives

["name"]=> string(7) "data.js"
["type"]=> string(22) "application/javascript"
["tmp_name"]=> string(35) "C:\easyphp\binaries\tmp\php21D0.tmp"
["error"]=> int(0)
["size"]=> int(12253)

Edit 2:

As @searaw noted, it seems that the assumption of validation is wrong.

And after digging in the method validateMimesinvendor\laravel\framework\src\Illuminate\Validation\Validator.php

and resetting the assumption variable dd($value->guessExtension()), I got txtmime -_-, which worked

+4
source share
1 answer

Ok. , Laravel, , . , Validator , , validateMimes Validator. , . mime, , finfo PHP mime. , mime, mime , , mime . Validator, , "", . !

, , , mime.

'application/java-archive' => 'jar',
'application/java-serialized-object' => 'ser',
'application/java-vm' => 'class',
'application/javascript' => 'js',
'application/json' => 'json',
'application/jsonml+json' => 'jsonml',

javascript. , , , mime- . , javascript. , mime, .

, javascript, mime_content_type(), text/plain. , Laravel.

, !

+4

All Articles