webCOMAND

mime_type::get_extension_from_data()

Get the file extension of a file format based on file data.

Prototype

string get_extension_from_data(string $data)

Parameters

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

Return

A string containing the file extension, in all lowercase, and without the dot.  For example, "pdf".

Example

// print the file extension based on file data
$filename = 'article.pdf';
$data = file_get_contents($filename);
$ext = \io_comand_util\mime_type::get_extension_from_data($data);
echo("File extension for $filename is $ext");