5

filemimetype

file_mime_type
SYNOPSIS

file_mime_type($file, $encoding=true)

DESCRIPTION
CODE
  1. function file_mime_type($file, $encoding=true) {
  2.     $mime=false;
  3.  
  4.     if (function_exists('finfo_file')) {
  5.         $finfo = finfo_open(FILEINFO_MIME);
  6.         $mime = @finfo_file($finfo, $file);
  7.         finfo_close($finfo);
  8.     }
  9.     else if (substr(PHP_OS, 0, 3) == 'WIN') {
  10.         $mime = mime_content_type($file);
  11.     }
  12.     else {
  13.         $file = escapeshellarg($file);
  14.         $cmd = "file -iL $file";
  15.  
  16.         exec($cmd, $output, $r);
  17.  
  18.         if ($r == 0) {
  19.             $mime = substr($output[0], strpos($output[0], ': ')+2);
  20.         }
  21.     }
  22.  
  23.     if (!$mime) {
  24.         return false;
  25.     }
  26.  
  27.     if ($encoding) {
  28.         return $mime;
  29.     }
  30.  
  31.     return substr($mime, 0, strpos($mime, '; '));
  32. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].