Jump to content

How to get the mime type of a file


jordanwb

Recommended Posts

I tried the first one using a function that was created by someone there and I get this error:

 

Fatal error: Call to undefined function finfo_open() in D:\xampp\htdocs\jproxy\includes\file_parser.php on line 31

 

For mime_content_type I don't get any results:

 

function output ()
{
$num_lines = count ($this->html);
$mime_type = mime_content_type ($this->file);
print $mime_type;
//header("Content-type:".$mime_type);
//print_r ($this->html);
}

 

$this->file is created in the constructor and the path is correct. Perhaps mime_content_type doesn't work with files that are on another server?


<?php
function output ()
{
$num_lines = count ($this->html);

$finfo = finfo_open(FILEINFO_MIME); 
$mime_type = finfo_file($finfo, $this->file);
finfo_close($finfo);

print $mime_type;
//header("Content-type:".$mime_type);
//print_r ($this->html);
}
?>

You have to have it installed and that's why I gave you this link with installation instructions: http://us2.php.net/manual/en/ref.fileinfo.php

 

The other function as per docs state that magic.mime file is needed/used.

 

The code example in the manual shows specifying a path and not a URL, so I don't think you can get the mime type from another server if that's what you're trying to do.

 

 

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.