PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/xnews/class/class.mimetype.php

https://github.com/severnaya99/Sg-2010
PHP | 262 lines | 179 code | 10 blank | 73 comment | 3 complexity | c6c3f070fac607ca969eeaab2a4a4e07 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. Copyright (C) 2002 Jason Sheets <jsheets@shadonet.com>.
  4. All rights reserved.
  5. THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions
  8. are met:
  9. 1. Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. 2. Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in the
  13. documentation and/or other materials provided with the distribution.
  14. 3. Neither the name of the project nor the names of its contributors
  15. may be used to endorse or promote products derived from this software
  16. without specific prior written permission.
  17. THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  18. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  21. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. SUCH DAMAGE.
  28. **/
  29. /**
  30. Name: PHP MimeType Class
  31. Version: 1.0
  32. Date Released: 10/20/02
  33. Description: This class allows a PHP script to determine the mime type
  34. a file based on the file extension. This class is handy for PHP versions
  35. without the benefit of other tools to determine the mime type. The class
  36. defaults to octet-stream so if the file type is not recognized the user
  37. is presented with a file download prompt.
  38. NOTES: The mime types for this version are based on Apache 1.3.27
  39. mime types may change or need to be added in the future, the mime types
  40. are stored in an array so that an awk or other script can automatically
  41. generate the code to make the array.
  42. Usage:
  43. First an instance of the mimetype class must be created, then the
  44. getType method should be called with the filename. It will return
  45. the mime type, an example follows.
  46. Example:
  47. $mimetype = new mimetype();
  48. print $mimetype->getType('acrobat.pdf');
  49. Author: Jason Sheets <jsheets@shadonet.com>
  50. License: This script is distributed under the BSD License, you are free
  51. to use, or modify it however you like. If you find this script useful please
  52. e-mail me.
  53. **/
  54. if (!defined('XOOPS_ROOT_PATH')) {
  55. die("XOOPS root path not defined");
  56. }
  57. class nw_cmimetype
  58. {
  59. function getType($filename) {
  60. // get base name of the filename provided by user
  61. $filename = basename($filename);
  62. // break file into parts seperated by .
  63. $filename = explode('.', $filename);
  64. // take the last part of the file to get the file extension
  65. $filename = $filename[count($filename)-1];
  66. // find mime type
  67. return $this->privFindType($filename);
  68. }
  69. function privFindType($ext) {
  70. // create mimetypes array
  71. $mimetypes = $this->privBuildMimeArray();
  72. // return mime type for extension
  73. if (isset($mimetypes[$ext])) {
  74. return $mimetypes[$ext];
  75. // if the extension wasn't found return octet-stream
  76. } else {
  77. return 'unknown';
  78. }
  79. }
  80. function privBuildMimeArray() {
  81. return array(
  82. "ez" => "application/andrew-inset",
  83. "hqx" => "application/mac-binhex40",
  84. "cpt" => "application/mac-compactpro",
  85. "doc" => "application/msword",
  86. "DOC" => "application/msword",
  87. "Doc" => "application/msword",
  88. "xls" => "application/vnd.ms-excel",
  89. "Xls" => "application/vnd.ms-excel",
  90. "XLS" => "application/vnd.ms-excel",
  91. "bin" => "application/octet-stream",
  92. "dms" => "application/octet-stream",
  93. "lha" => "application/octet-stream",
  94. "lzh" => "application/octet-stream",
  95. "exe" => "application/octet-stream",
  96. "class" => "application/octet-stream",
  97. "so" => "application/octet-stream",
  98. "dll" => "application/octet-stream",
  99. "oda" => "application/oda",
  100. "pdf" => "application/pdf",
  101. "PDF" => "application/pdf",
  102. "Pdf" => "application/pdf",
  103. "ai" => "application/postscript",
  104. "eps" => "application/postscript",
  105. "ps" => "application/postscript",
  106. "smi" => "application/smil",
  107. "smil" => "application/smil",
  108. "wbxml" => "application/vnd.wap.wbxml",
  109. "wmlc" => "application/vnd.wap.wmlc",
  110. "wmlsc" => "application/vnd.wap.wmlscriptc",
  111. "bcpio" => "application/x-bcpio",
  112. "vcd" => "application/x-cdlink",
  113. "pgn" => "application/x-chess-pgn",
  114. "cpio" => "application/x-cpio",
  115. "csh" => "application/x-csh",
  116. "dcr" => "application/x-director",
  117. "dir" => "application/x-director",
  118. "dxr" => "application/x-director",
  119. "dvi" => "application/x-dvi",
  120. "spl" => "application/x-futuresplash",
  121. "gtar" => "application/x-gtar",
  122. "hdf" => "application/x-hdf",
  123. "js" => "application/x-javascript",
  124. "skp" => "application/x-koan",
  125. "skd" => "application/x-koan",
  126. "skt" => "application/x-koan",
  127. "skm" => "application/x-koan",
  128. "latex" => "application/x-latex",
  129. "nc" => "application/x-netcdf",
  130. "cdf" => "application/x-netcdf",
  131. "sh" => "application/x-sh",
  132. "shar" => "application/x-shar",
  133. "swf" => "application/x-shockwave-flash",
  134. "sit" => "application/x-stuffit",
  135. "sv4cpio" => "application/x-sv4cpio",
  136. "sv4crc" => "application/x-sv4crc",
  137. "tar" => "application/x-tar",
  138. "tcl" => "application/x-tcl",
  139. "tex" => "application/x-tex",
  140. "texinfo" => "application/x-texinfo",
  141. "texi" => "application/x-texinfo",
  142. "t" => "application/x-troff",
  143. "tr" => "application/x-troff",
  144. "roff" => "application/x-troff",
  145. "man" => "application/x-troff-man",
  146. "me" => "application/x-troff-me",
  147. "ms" => "application/x-troff-ms",
  148. "ustar" => "application/x-ustar",
  149. "src" => "application/x-wais-source",
  150. "xhtml" => "application/xhtml+xml",
  151. "xht" => "application/xhtml+xml",
  152. "zip" => "application/x-zip-compressed",
  153. "Zip" => "application/x-zip-compressed",
  154. "ZIP" => "application/x-zip-compressed",
  155. "au" => "audio/basic",
  156. "XM" => "audio/fasttracker",
  157. "snd" => "audio/basic",
  158. "mid" => "audio/midi",
  159. "midi" => "audio/midi",
  160. "kar" => "audio/midi",
  161. "mpga" => "audio/mpeg",
  162. "mp2" => "audio/mpeg",
  163. "mp3" => "audio/mpeg",
  164. "aif" => "audio/x-aiff",
  165. "aiff" => "audio/x-aiff",
  166. "aifc" => "audio/x-aiff",
  167. "m3u" => "audio/x-mpegurl",
  168. "ram" => "audio/x-pn-realaudio",
  169. "rm" => "audio/x-pn-realaudio",
  170. "rpm" => "audio/x-pn-realaudio-plugin",
  171. "ra" => "audio/x-realaudio",
  172. "wav" => "audio/x-wav",
  173. "wax" => "audio/x-windows-media",
  174. "pdb" => "chemical/x-pdb",
  175. "xyz" => "chemical/x-xyz",
  176. "bmp" => "image/bmp",
  177. "gif" => "image/gif",
  178. "ief" => "image/ief",
  179. "jpeg" => "image/pjpeg",
  180. "jpeg" => "image/jpeg",
  181. "jpg" => "image/jpeg",
  182. "jpe" => "image/jpeg",
  183. "png" => "image/x-png",
  184. "tiff" => "image/tiff",
  185. "tif" => "image/tif",
  186. "ico" => "image/icon",
  187. "djvu" => "image/vnd.djvu",
  188. "djv" => "image/vnd.djvu",
  189. "wbmp" => "image/vnd.wap.wbmp",
  190. "ras" => "image/x-cmu-raster",
  191. "pnm" => "image/x-portable-anymap",
  192. "pbm" => "image/x-portable-bitmap",
  193. "pgm" => "image/x-portable-graymap",
  194. "ppm" => "image/x-portable-pixmap",
  195. "rgb" => "image/x-rgb",
  196. "xbm" => "image/x-xbitmap",
  197. "xpm" => "image/x-xpixmap",
  198. "xwd" => "image/x-windowdump",
  199. "igs" => "model/iges",
  200. "iges" => "model/iges",
  201. "msh" => "model/mesh",
  202. "mesh" => "model/mesh",
  203. "silo" => "model/mesh",
  204. "wrl" => "model/vrml",
  205. "vrml" => "model/vrml",
  206. "css" => "text/css",
  207. "html" => "text/html",
  208. "htm" => "text/html",
  209. "asc" => "text/plain",
  210. "txt" => "text/plain",
  211. "Log" => "text/plain",
  212. "log" => "text/plain",
  213. "rtx" => "text/richtext",
  214. "rtf" => "text/rtf",
  215. "sgml" => "text/sgml",
  216. "sgm" => "text/sgml",
  217. "tsv" => "text/tab-seperated-values",
  218. "wml" => "text/vnd.wap.wml",
  219. "wmls" => "text/vnd.wap.wmlscript",
  220. "etx" => "text/x-setext",
  221. "xml" => "text/xml",
  222. "xsl" => "text/xml",
  223. "mpeg" => "video/mpeg",
  224. "mpg" => "video/mpeg",
  225. "mpe" => "video/mpeg",
  226. "qt" => "video/quicktime",
  227. "mov" => "video/quicktime",
  228. "mxu" => "video/vnd.mpegurl",
  229. "avi" => "video/x-msvideo",
  230. "movie" => "video/x-sgi-movie",
  231. "php" => "text/php",
  232. "php3" => "text/php3",
  233. "ice" => "x-conference-xcooltalk",
  234. "unknown" => "application/octet-stream"
  235. );
  236. }
  237. }
  238. ?>