webCOMAND

mime_type::get_mime_type_from_data()

Get a MIME Type based on file data, such as the contents of a PDF file.  If the data is not recognized, "application/octet-stream" will be returned.

Prototype

string get_mime_type_from_data(string $data)

Parameters

  • data - A string containing the text or binary data of a file.

Return

A MIME Type like "application/pdf".  If the data is not recognized, "application/octet-stream" will be returned.

Example

// print MIME Type based on a file data
$filename = 'article.pdf';
$data = file_get_contents($filename);
$mime_type = \io_comand_util\mime_type::get_mime_type_from_data($data);
echo("MIME Type of $filename is $mime_type");