A
A
Alexander N++2015-01-27 16:20:32
PHP
Alexander N++, 2015-01-27 16:20:32

PHP $_FILES[filename][type], mime type trustworthy?

At me files at loading through the form are checked on mime type the list of resolved types.
1 So is it worth believing this information?
The fact is that the finfo extension does not correctly give the mime type, mp4 mp3 file.

$info = finfo_open(FILEINFO_MIME_TYPE, $magicFile);

        if ($info) {
            $result = finfo_file($info, $file);
            finfo_close($info);

            if ($result !== false) {
                return $result;
            }
        }

Previously, only images were uploaded, they were checked through finfo and that was enough.
2 If anyone knows how to make finfo normally say that mp3 is audio / mp3 audio / mpeg I will be very grateful.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2015-01-27
@AloneCoder

For audio, you can pull out id3 tags
getid3.sourceforge.net

A
Anton Shamanov, 2015-01-27
@SilenceOfWinter

Since PHP >= 5.3.11 and >= 5.4.1 the magic database format has changed. As a consequence, the internal mime database has also been updated. This especially affects the code where the external magic base is read. Reading old format magic files will not work. Some textual representations of mime types have also been changed, for example PHP will return "PHP script, ASCII text" instead of "PHP script text".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question