Source for file mime-types.php

Documentation is available at mime-types.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: mime-types.php */
  22. /* Author: Paul Waite */
  23. /* Description: Mime types for usage within Axyl. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package core *//** TEXT */
  27. ("CONTENT_TEXT", "text/plain");
  28. /** HTML attachments */
  29. ("CONTENT_HTML", "text/html");
  30. /** XML attachments */
  31. ("CONTENT_XML", "text/xml");
  32. /** CSV attachments */
  33. ("CONTENT_CSV", "text/csv");
  34.  
  35. // IMAGES
  36. /** Jpeg image attachment */
  37. ("CONTENT_JPEG", "image/jpeg");
  38. /** Photo Jpeg image attachment */
  39. ("CONTENT_PHOTO", "image/pjpeg");
  40. /** GIF attachment */
  41. ("CONTENT_GIF", "image/gif");
  42. /** PNG attachment */
  43. ("CONTENT_PNG", "image/png");
  44. /** BMP attachment */
  45. ("CONTENT_BMP", "image/bmp");
  46. /** TIFF attachment */
  47. ("CONTENT_TIFF", "image/tiff");
  48.  
  49. // MISC. BINARIES/EXECUTABLES
  50. /** Binaries of questionable parentage */
  51. ("CONTENT_OCTET", "application/octet-stream");
  52.  
  53. // MICROSOFT
  54. /** EXE files, binaries of poor parentage */
  55. ("CONTENT_MSDOS", "application/x-msdos-program");
  56. /** M$ Word docs */
  57. ("CONTENT_MSWORD", "application/msword");
  58. /** M$ Excel spreadsheets */
  59. ("CONTENT_MSEXCEL", "application/vnd.ms-excel");
  60. /** M$ Project files */
  61. ("CONTENT_MSPROJECT", "application/vnd.ms-project");
  62. /** M$ Word docs */
  63. ("CONTENT_MSACCESS", "application/msaccess");
  64.  
  65. // DOCUMENTS
  66. /** Adobe PDF's */
  67. ("CONTENT_PDF", "application/pdf");
  68. /** Postscript format */
  69. ("CONTENT_PSCRIPT", "application/postscript");
  70. /** Rich text format */
  71. ("CONTENT_RTF", "application/rtf");
  72. /** Tex format */
  73. ("CONTENT_TEX", "application/x-tex");
  74. /** Latex format */
  75. ("CONTENT_LATEX", "application/x-latex");
  76.  
  77. // ARCHIVE
  78. /** ZIP archive */
  79. ("CONTENT_ZIP", "application/zip");
  80.  
  81. // AUDIO
  82. /** AU/SND basic audio files */
  83. ("CONTENT_AUDIO", "audio/basic");
  84. /** MP3 audio files */
  85. ("CONTENT_MP3", "audio/mpeg");
  86. /** AIFF sound files */
  87. ("CONTENT_AIFF", "audio/x-aiff");
  88. /** WAV sound files */
  89. ("CONTENT_WAV", "audio/x-wav");
  90. /** REALAUDIO sound files */
  91. ("CONTENT_RA", "audio/x-realaudio");
  92. /** OGG sound files */
  93. ("CONTENT_OGG", "audio/x-ogg");
  94.  
  95. // MOVIES
  96. /** MPEG Movies */
  97. ("CONTENT_MPEG", "video/mpeg");
  98. /** AVI Movies */
  99. ("CONTENT_AVI", "video/x-msvideo");
  100. /** Media player ASF, ASX Movies */
  101. ("CONTENT_ASF", "video/x-ms-asf");
  102. /** Quicktime movies */
  103. ("CONTENT_QUICKTIME", "video/quicktime");
  104. /** Shockwave Flash movies */
  105. ("CONTENT_FLASH", "application/x-shockwave-flash");
  106. /** Windows Media Player */
  107. ("CONTENT_WINMEDIA", "application/x-mplayer2");
  108.  
  109. // .........................................................................
  110. // Mime type groupings
  111.  
  112. define("IMAGE_MIMES",
  113. CONTENT_JPEG . ","
  114. . CONTENT_PHOTO . ","
  115. . CONTENT_GIF . ","
  116. . CONTENT_PNG . ","
  117. . CONTENT_BMP . ","
  118. . CONTENT_TIFF
  119. );
  120. define("DOCUMENT_MIMES",
  121. CONTENT_TEXT . ","
  122. . CONTENT_HTML . ","
  123. . CONTENT_XML . ","
  124. . CONTENT_TEX . ","
  125. . CONTENT_LATEX . ","
  126. . CONTENT_CSV . ","
  127. . CONTENT_MSWORD . ","
  128. . CONTENT_MSEXCEL . ","
  129. . CONTENT_PDF . ","
  130. . CONTENT_PSCRIPT . ","
  131. . CONTENT_RTF
  132. );
  133. define("AUDIO_MIMES",
  134. CONTENT_AUDIO . ","
  135. . CONTENT_MP3 . ","
  136. . CONTENT_AIFF . ","
  137. . CONTENT_WAV . ","
  138. . CONTENT_RA . ","
  139. . CONTENT_OGG
  140. );
  141. define("MOVIE_MIMES",
  142. CONTENT_MPEG . ","
  143. . CONTENT_AVI . ","
  144. . CONTENT_ASF . ","
  145. . CONTENT_QUICKTIME
  146. );
  147. define("FLASH_MIMES",
  148. CONTENT_FLASH
  149. );
  150. define("ALL_MIMES",
  151. IMAGE_MIMES . ","
  152. . DOCUMENT_MIMES . ","
  153. . AUDIO_MIMES . ","
  154. . MOVIE_MIMES
  155. );
  156.  
  157. // .........................................................................
  158. // Mimetype grouping values and descriptions
  159.  
  160. $mime_categories = array(
  161. "image" => "Images",
  162. "document" => "Documents",
  163. "audio" => "Audio",
  164. "movie" => "Movies",
  165. "flash" => "Flash"
  166. );
  167.  
  168. // .........................................................................
  169. // Mime types by file extension
  170.  
  171. $extn_mimetypes = array(
  172. "au" => CONTENT_AUDIO,
  173. "snd" => CONTENT_AUDIO,
  174. "mp3" => CONTENT_MP3,
  175. "aif" => CONTENT_AIFF,
  176. "aiff" => CONTENT_AIFF,
  177. "aifc" => CONTENT_AIFF,
  178. "wav" => CONTENT_WAV,
  179. "ogg" => CONTENT_OGG,
  180. "ra" => CONTENT_RA,
  181. "ram" => CONTENT_RA,
  182. "mpg" => CONTENT_MPEG,
  183. "mpe" => CONTENT_MPEG,
  184. "mpeg" => CONTENT_MPEG,
  185. "avi" => CONTENT_AVI,
  186. "asf" => CONTENT_ASF,
  187. "asx" => CONTENT_ASF,
  188. "mov" => CONTENT_QUICKTIME,
  189. "qt" => CONTENT_QUICKTIME,
  190. "qtm" => CONTENT_QUICKTIME,
  191. "swf" => CONTENT_FLASH,
  192. "zip" => CONTENT_ZIP,
  193. "txt" => CONTENT_TEXT,
  194. "html" => CONTENT_HTML,
  195. "htm" => CONTENT_HTML,
  196. "xml" => CONTENT_XML,
  197. "csv" => CONTENT_CSV,
  198. "tex" => CONTENT_TEX,
  199. "latex" => CONTENT_LATEX,
  200. "jfif" => CONTENT_JPEG,
  201. "jpg" => CONTENT_JPEG,
  202. "jpeg" => CONTENT_JPEG,
  203. "pjpeg" => CONTENT_PHOTO,
  204. "gif" => CONTENT_GIF,
  205. "png" => CONTENT_PNG,
  206. "bmp" => CONTENT_BMP,
  207. "tif " => CONTENT_TIFF,
  208. "tiff " => CONTENT_TIFF,
  209. "exe" => CONTENT_MSDOS,
  210. "doc" => CONTENT_MSWORD,
  211. "xls" => CONTENT_MSEXCEL,
  212. "mpp" => CONTENT_MSPROJECT,
  213. "mdb" => CONTENT_MSACCESS,
  214. "pdf" => CONTENT_PDF,
  215. "rtf" => CONTENT_RTF,
  216. "ps" => CONTENT_PSCRIPT,
  217. "eps" => CONTENT_PSCRIPT,
  218. "ai" => CONTENT_PSCRIPT,
  219. "" => CONTENT_OCTET
  220. );
  221.  
  222. // .........................................................................
  223. /**
  224. * Returns the category associated with the given mimetype. This just
  225. * allows you to ascertain what basic group of objects the mimetype
  226. * belongs to, like 'image', 'document', 'movie', 'sound', etc.
  227. * @param string $mimetype The mimetype to categorise.
  228. * @return string The overall mime category name
  229. */
  230. function mimetype_category($mimetype="") {
  231. $cat = "";
  232. if ($mimetype != "") {
  233. $mimetype = strtolower(trim($mimetype));
  234. if (strstr(IMAGE_MIMES, $mimetype)) $cat = "image";
  235. elseif (strstr(DOCUMENT_MIMES, $mimetype)) $cat = "document";
  236. elseif (strstr(AUDIO_MIMES, $mimetype)) $cat = "audio";
  237. elseif (strstr(MOVIE_MIMES, $mimetype)) $cat = "movie";
  238. elseif (strstr(FLASH_MIMES, $mimetype)) $cat = "flash";
  239. }
  240. return $cat;
  241. } // mimetype_category
  242. // .........................................................................
  243.  
  244. /**
  245. * Returns the mimetype associated with the given filepath
  246. * or false of no match was found..
  247. * @param string $extn The file extension, eg: '.gif' etc.
  248. * @return string The mimetype of the given file
  249. */
  250. function mimetype_from_filename($path="") {
  251. global $extn_mimetypes;
  252. $rc = false;
  253. $extn = get_file_extn($path);
  254. if ($extn != "") {
  255. if (isset($extn_mimetypes[$extn])) {
  256. $rc = $extn_mimetypes[$extn];
  257. }
  258. }
  259. return $rc;
  260. } // mimetype_from_filename
  261. // -------------------------------------------------------------------------
  262.  
  263. ?>

Documentation generated by phpDocumentor 1.3.0RC3