webCOMAND

mime_type::get_mime_type_from_file()

Get a MIME Type for a file based on the filename, or the file contents if the file exists and the file extension is not recognized.  If the file extension is recognized, that will be used without verifying the file contents match.

Prototype

string get_mime_type_from_file(string $filename)

Parameters

  • filename - A filename or file path.  A relative or absolute file path may be provided.

Return

A MIME Type like 'application/pdf'.

Example

// print the MIME Type from a filename
$filename = 'article.pdf';
$mime_type = \io_comand_util\mime_type::get_mime_type_from_file($filename);
echo("MIME Type for file $filename is $mime_type");