datnt0302's avatar

Can not validate mimes

I try to use rule mimes:csv,txt,xls for validate upload file, everything seem ok till i upload one file with this content and in shift jis encode,

some japanese char,some japanese char,8,n16,AN0001,N00001,auto,2023-04-03,8,8,,,,,,,,,,,,,,
some japanese char,some japanese char,8,n16,AN0001,N00001,auto,2023-04-03,8,8,,,,,,,,,,,,,,

some japanese char,some japanese char,8,n16,AN0001,N00001,auto,2023-04-03,8,8,,,,,,,,,,,,,,

some japanese char,some japanese char,8,n16,AN0001,N00001,auto,2023-04-03,8,8,,,,,,,,,,,,,,

some japanese char,some japanese char,8,n16,AN0001,N00001,auto,2023-04-03,8,8,,,,,,,,,,,,,,

The file: https://gist.github.com/SentryoZ/e98c47bdb2cbecc0fa0a5476e92523d1

i tried to debug then found out guessExtension() is return null value

Using laravel 8.83.27

0 likes
1 reply
s4muel's avatar

thats weird, japanese characters should be no problem and if you replace them, you still wont get the mime type.

problem is imho in this code (library used to get mime type from file): https://github.com/thephpleague/flysystem/blob/3.x/src/Local/FallbackMimeTypeDetector.php#L45

it first detects the mime by finfo() and gets back text/plain, but because this is in the INCONCLUSIVE_MIME_TYPES list, it tries to get the mime from the extension. and since your file probably doesn't have one, the library returns null/false in the end.

i am not sure this was the intention of the library creator, but this is the way it currently works.

you probably get more info if you open a discussion on github for the library.

1 like

Please or to participate in this conversation.