View Full Version : Getting mime-type from file (or its .ext)

03-11-2003, 07:35 PM
I am pretty sure this can be done as it is mentioed in the docs (but as always, it talks mainly about UNIX !!)
Is there a built-in function that will return the mime-type in the form "text/plain" based upon the filedata or extension of a file on the server.
I have tried the mime_content_type(String filename) function, but an undefined function error is returned when i try to use it on my win32 system.

Failing the existance of a built in function, how easy would it be to write one, assuming the default file extensions for all mime types??


Dylan Leblanc
03-11-2003, 11:06 PM
If nothing else you could make an array of all MIME types (or at least all the ones you need to deal with), and do something like this:

$allcontenttypes = array(
'png' => 'image/png',
'pdf' => 'application/pdf'

$fileextension = substr($filename, -3);

$contenttype = $allcontenttypes[$fileextension];