Incorrect/undesirable ogv MIME type from PHP fileinfo

252 views Asked by At

I tried this on most of the servers I have, and PHP seems to return application/ogg for ogv video files. This is strange, because the Apache mime config file clearly lists video/ogg (also not desirable, but at least it would make sense since the info is supposed to be coming from there). Originally I encountered this problem in Responsive File Manager, but was able to reproduce it independently.

The code:

$fileinfo = finfo_open(FILEINFO_MIME);
$mime_type = finfo_file($fileinfo, $file);
finfo_close($fileinfo);

var_dump($mime_type);

The output:

string(31) "application/ogg; charset=binary"

Where is this information coming from, and how can I change it?

Putting .htaccess directives doesn't seem to help at all. It probably also matters that I am running cPanel/WHM, but wasn't able to find any additional relevant configuration. Moreover, cPanel also gives video/ogg for ogv, just like Apache.

1

There are 1 answers

1
Mike S On

The finfo_file is using the Linux file command: https://linux.die.net/man/1/file

Output of finfo_file:

application/ogg; charset=binary

Output of file -i sample.ogv

application/ogg; charset=binary

One solution is to use apache_lookup_uri which sounds like it may work for you since you're running on Apache: http://php.net/apache_lookup_uri

var_dump( apache_lookup_uri('sample.ogv') );

object(stdClass)#1 (16) {
  ["status"]=>
  int(200)
  ["the_request"]=>
  string(27) "GET /tmp/test.php HTTP/1.1"
  ["method"]=>
  string(3) "GET"
  ["mtime"]=>
  int(0)
  ["clength"]=>
  int(0)
  ["chunked"]=>
  int(0)
  ["content_type"]=>
  string(9) "video/ogg"
  ["no_cache"]=>
  int(0)
  ["no_local_copy"]=>
  int(1)
  ["unparsed_uri"]=>
  string(16) "/mime/sample.ogv"
  ["uri"]=>
  string(16) "/mime/sample.ogv"
  ["filename"]=>
  string(48) "/tmp/sample.ogv"
  ["allowed"]=>
  int(0)
  ["sent_bodyct"]=>
  int(0)
  ["bytes_sent"]=>
  int(0)
  ["request_time"]=>
  int(1504107700)
}