Posted By

fackz on 01/22/09


Tagged

file type mime


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

Scooter
umang_nine
fackz
BrianCoyDesign
d0ri0


get file mime-type


 / Published in: PHP
 

You only use the filename as $value for get_mimetype().

  1. function get_file_extension($file) {
  2.  
  3. return array_pop(explode('.',$file));
  4. }
  5.  
  6. function get_mimetype($value='') {
  7.  
  8. $ct['htm'] = 'text/html';
  9. $ct['html'] = 'text/html';
  10. $ct['txt'] = 'text/plain';
  11. $ct['asc'] = 'text/plain';
  12. $ct['bmp'] = 'image/bmp';
  13. $ct['gif'] = 'image/gif';
  14. $ct['jpeg'] = 'image/jpeg';
  15. $ct['jpg'] = 'image/jpeg';
  16. $ct['jpe'] = 'image/jpeg';
  17. $ct['png'] = 'image/png';
  18. $ct['ico'] = 'image/vnd.microsoft.icon';
  19. $ct['mpeg'] = 'video/mpeg';
  20. $ct['mpg'] = 'video/mpeg';
  21. $ct['mpe'] = 'video/mpeg';
  22. $ct['qt'] = 'video/quicktime';
  23. $ct['mov'] = 'video/quicktime';
  24. $ct['avi'] = 'video/x-msvideo';
  25. $ct['wmv'] = 'video/x-ms-wmv';
  26. $ct['mp2'] = 'audio/mpeg';
  27. $ct['mp3'] = 'audio/mpeg';
  28. $ct['rm'] = 'audio/x-pn-realaudio';
  29. $ct['ram'] = 'audio/x-pn-realaudio';
  30. $ct['rpm'] = 'audio/x-pn-realaudio-plugin';
  31. $ct['ra'] = 'audio/x-realaudio';
  32. $ct['wav'] = 'audio/x-wav';
  33. $ct['css'] = 'text/css';
  34. $ct['zip'] = 'application/zip';
  35. $ct['pdf'] = 'application/pdf';
  36. $ct['doc'] = 'application/msword';
  37. $ct['bin'] = 'application/octet-stream';
  38. $ct['exe'] = 'application/octet-stream';
  39. $ct['class']= 'application/octet-stream';
  40. $ct['dll'] = 'application/octet-stream';
  41. $ct['xls'] = 'application/vnd.ms-excel';
  42. $ct['ppt'] = 'application/vnd.ms-powerpoint';
  43. $ct['wbxml']= 'application/vnd.wap.wbxml';
  44. $ct['wmlc'] = 'application/vnd.wap.wmlc';
  45. $ct['wmlsc']= 'application/vnd.wap.wmlscriptc';
  46. $ct['dvi'] = 'application/x-dvi';
  47. $ct['spl'] = 'application/x-futuresplash';
  48. $ct['gtar'] = 'application/x-gtar';
  49. $ct['gzip'] = 'application/x-gzip';
  50. $ct['js'] = 'application/x-javascript';
  51. $ct['swf'] = 'application/x-shockwave-flash';
  52. $ct['tar'] = 'application/x-tar';
  53. $ct['xhtml']= 'application/xhtml+xml';
  54. $ct['au'] = 'audio/basic';
  55. $ct['snd'] = 'audio/basic';
  56. $ct['midi'] = 'audio/midi';
  57. $ct['mid'] = 'audio/midi';
  58. $ct['m3u'] = 'audio/x-mpegurl';
  59. $ct['tiff'] = 'image/tiff';
  60. $ct['tif'] = 'image/tiff';
  61. $ct['rtf'] = 'text/rtf';
  62. $ct['wml'] = 'text/vnd.wap.wml';
  63. $ct['wmls'] = 'text/vnd.wap.wmlscript';
  64. $ct['xsl'] = 'text/xml';
  65. $ct['xml'] = 'text/xml';
  66.  
  67. $extension = get_file_extension($value);
  68.  
  69. if (!$type = $ct[strtolower($extension)]) {
  70.  
  71. $type = 'text/html';
  72. }
  73.  
  74. return $type;
  75. }

Report this snippet  

You need to login to post a comment.