Poe
Poe

Reputation: 3010

video mimetype .mpg

I'm using a php function finfo_file to determine mimetype and it keeps reporting .mpg files as application/octet-stream instead of video/mpeg.

I'm using CentOS, and in /etc/mime.types I see:

# grep 'mpg' /etc/mime.types 
audio/mpeg          mpga mp2 mp3
video/mpeg          mpeg mpg mpe

Updated below is sample code:

$file = '/tmp/sample.mpg';
$fi = new finfo( FILEINFO_MIME_TYPE );
echo $fi->file( $file );

outputs:

application/octet-stream

Upvotes: 2

Views: 2194

Answers (1)

Michael Hampton
Michael Hampton

Reputation: 10000

These PHP functions depend on supplying a magic file which provides data to analyze a file's content to determine its type. On a Unix system, this functionality is exposed via the file command.

At no time does it ever look at /etc/mime.types.

Since you didn't specify a path to the magic file in your constructor, PHP uses /usr/share/misc/magic by default. In CentOS, this file is provided by the file-libs package. If the package is missing or corrupt, you may get unexpected results.

Upvotes: 2

Related Questions