user1559811
user1559811

Reputation: 449

.flv and .f4v file extensions displaying unexpected mime type

When I look up the mime types of my .flv and f4v in php it states them as: application/octet-stream.

I always thought the mime types for these files were 'video/x-flv' and 'video/x-f4v'. Is this a new thing or are the files coming from a funky source or something?

Upvotes: 1

Views: 2818

Answers (2)

trejder
trejder

Reputation: 17505

I have had a similar problem. FileInfo on board my PHP 5.4.7 (in XAMPP under Windows) is able to detect .flv file as video/x-flv, but fails on .mkv video (should detect it as video/x-matroska, but returns application/octet-stream instead) and many other non-typical multimedia formats.

To solve this problem I dropped FileInfo at all and reverted back to old, good mime-by-extension method, using following function:

public static function getMimeTypeByExtension($file)
{
    $extensions = require('mimeTypes.php');

    if(($ext=pathinfo($file, PATHINFO_EXTENSION))!=='')
    {
        $ext=strtolower($ext);
        if(isset($extensions[$ext]))
            return $extensions[$ext];
    }
    return null;
}

Contents of mimeTypes.php you can find at pastebin.com. It is compiled by me, by merging Apache SVN's mime.types file and similar mimeTypes.php array from Yii Framework. Resulting set has over 1000 relations between file extension and coresponding MIME-type.

Importan note: Before using this solution, you must carefully consider, what purpose you need it for? MIME-type based on file extension can be very easily spoofed, by simply changing that extension. So any security-related piece of code should be kept far as possible from my solution.

I needed it only for simple purpose of providing correct MIME-type of video file for flowplayer. I assumed that, if user change extension of such file to something else, then flowplayer will simply fail to playback that movie.

Upvotes: 0

Jeremy Thompson
Jeremy Thompson

Reputation: 65702

I mention in this answer that both Winista and URLMon dont detect swf's or flv's properly. This is why the php component you're using cant fully identify the 'video/x-flv' and 'video/x-f4v' files.

Winista uses a magic file (that contains a list of MIME types and respective hex chars that indicate the starting bits of particular files).

I suggest you focus on why no-one else has been able to add flv detection to this magic file. The winista project to is a port from an old Java open source project.

The only other thought I have is trying ffmpeg, maybe it has the smarts to detect the exact MIME Type of these flv and f4v files.

Upvotes: 1

Related Questions