Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: File extension to MIME type? [duplicate]

Tags:

file

php

mime

Possible Duplicate:
How do I determine the extension(s) associated with a MIME type in PHP?

I'm aware of how to get the MIME type of a given file, but is there a way to do it given only an extension?

Example input:

jpg

Example output:

image/jpeg
like image 941
FtDRbwLXw6 Avatar asked Jul 18 '12 15:07

FtDRbwLXw6


2 Answers

try this to get info about which extension is which mime type, but of course please be aware that this won't be very accurate (e.g. possible gif file on png extension..)

like image 73
Jerzy Zawadzki Avatar answered Oct 04 '22 21:10

Jerzy Zawadzki


The most elegant solution I've seen for Apache environments is http://www.php.net/manual/en/function.mime-content-type.php#107798

like image 28
Ross Smith II Avatar answered Oct 04 '22 22:10

Ross Smith II