PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-includes/mimetype.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 241 lines | 159 code | 9 blank | 73 comment | 2 complexity | 64df4c1c13525a2b2fc2f5c5c9d5bb57 MD5 | raw file
  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. class mimetype {
  55. function getType($filename) {
  56. // get base name of the filename provided by user
  57. $filename = basename($filename);
  58. // break file into parts seperated by .
  59. $filename = explode('.', $filename);
  60. // take the last part of the file to get the file extension
  61. $filename = $filename[count($filename)-1];
  62. // find mime type
  63. return $this->privFindType($filename);
  64. }
  65. function privFindType($ext) {
  66. // create mimetypes array
  67. $mimetypes = $this->privBuildMimeArray();
  68. // return mime type for extension
  69. if (isset($mimetypes[$ext])) {
  70. return $mimetypes[$ext];
  71. // if the extension wasn't found return octet-stream
  72. } else {
  73. return 'application/octet-stream';
  74. }
  75. }
  76. function privBuildMimeArray() {
  77. return array(
  78. "ez" => "application/andrew-inset",
  79. "hqx" => "application/mac-binhex40",
  80. "cpt" => "application/mac-compactpro",
  81. "doc" => "application/msword",
  82. "bin" => "application/octet-stream",
  83. "dms" => "application/octet-stream",
  84. "lha" => "application/octet-stream",
  85. "lzh" => "application/octet-stream",
  86. "exe" => "application/octet-stream",
  87. "class" => "application/octet-stream",
  88. "so" => "application/octet-stream",
  89. "dll" => "application/octet-stream",
  90. "oda" => "application/oda",
  91. "pdf" => "application/pdf",
  92. "ai" => "application/postscript",
  93. "eps" => "application/postscript",
  94. "ps" => "application/postscript",
  95. "smi" => "application/smil",
  96. "smil" => "application/smil",
  97. "wbxml" => "application/vnd.wap.wbxml",
  98. "wmlc" => "application/vnd.wap.wmlc",
  99. "wmlsc" => "application/vnd.wap.wmlscriptc",
  100. "bcpio" => "application/x-bcpio",
  101. "vcd" => "application/x-cdlink",
  102. "pgn" => "application/x-chess-pgn",
  103. "cpio" => "application/x-cpio",
  104. "csh" => "application/x-csh",
  105. "dcr" => "application/x-director",
  106. "dir" => "application/x-director",
  107. "dxr" => "application/x-director",
  108. "dvi" => "application/x-dvi",
  109. "spl" => "application/x-futuresplash",
  110. "gtar" => "application/x-gtar",
  111. "hdf" => "application/x-hdf",
  112. "js" => "application/x-javascript",
  113. "skp" => "application/x-koan",
  114. "skd" => "application/x-koan",
  115. "skt" => "application/x-koan",
  116. "skm" => "application/x-koan",
  117. "latex" => "application/x-latex",
  118. "nc" => "application/x-netcdf",
  119. "cdf" => "application/x-netcdf",
  120. "sh" => "application/x-sh",
  121. "shar" => "application/x-shar",
  122. "swf" => "application/x-shockwave-flash",
  123. "sit" => "application/x-stuffit",
  124. "sv4cpio" => "application/x-sv4cpio",
  125. "sv4crc" => "application/x-sv4crc",
  126. "tar" => "application/x-tar",
  127. "tcl" => "application/x-tcl",
  128. "tex" => "application/x-tex",
  129. "texinfo" => "application/x-texinfo",
  130. "texi" => "application/x-texinfo",
  131. "t" => "application/x-troff",
  132. "tr" => "application/x-troff",
  133. "roff" => "application/x-troff",
  134. "man" => "application/x-troff-man",
  135. "me" => "application/x-troff-me",
  136. "ms" => "application/x-troff-ms",
  137. "ustar" => "application/x-ustar",
  138. "src" => "application/x-wais-source",
  139. "xhtml" => "application/xhtml+xml",
  140. "xht" => "application/xhtml+xml",
  141. "zip" => "application/zip",
  142. "au" => "audio/basic",
  143. "snd" => "audio/basic",
  144. "mid" => "audio/midi",
  145. "midi" => "audio/midi",
  146. "kar" => "audio/midi",
  147. "mpga" => "audio/mpeg",
  148. "mp2" => "audio/mpeg",
  149. "mp3" => "audio/mpeg",
  150. "m4a" => "audio/mp4",
  151. "aif" => "audio/x-aiff",
  152. "aiff" => "audio/x-aiff",
  153. "aifc" => "audio/x-aiff",
  154. "m3u" => "audio/x-mpegurl",
  155. "ram" => "audio/x-pn-realaudio",
  156. "rm" => "audio/x-pn-realaudio",
  157. "rpm" => "audio/x-pn-realaudio-plugin",
  158. "ra" => "audio/x-realaudio",
  159. "wav" => "audio/x-wav",
  160. "pdb" => "chemical/x-pdb",
  161. "xyz" => "chemical/x-xyz",
  162. "bmp" => "image/bmp",
  163. "gif" => "image/gif",
  164. "ief" => "image/ief",
  165. "jpeg" => "image/jpeg",
  166. "jpg" => "image/jpeg",
  167. "jpe" => "image/jpeg",
  168. "png" => "image/png",
  169. "tiff" => "image/tiff",
  170. "tif" => "image/tif",
  171. "djvu" => "image/vnd.djvu",
  172. "djv" => "image/vnd.djvu",
  173. "wbmp" => "image/vnd.wap.wbmp",
  174. "ras" => "image/x-cmu-raster",
  175. "pnm" => "image/x-portable-anymap",
  176. "pbm" => "image/x-portable-bitmap",
  177. "pgm" => "image/x-portable-graymap",
  178. "ppm" => "image/x-portable-pixmap",
  179. "rgb" => "image/x-rgb",
  180. "xbm" => "image/x-xbitmap",
  181. "xpm" => "image/x-xpixmap",
  182. "xwd" => "image/x-windowdump",
  183. "igs" => "model/iges",
  184. "iges" => "model/iges",
  185. "msh" => "model/mesh",
  186. "mesh" => "model/mesh",
  187. "silo" => "model/mesh",
  188. "wrl" => "model/vrml",
  189. "vrml" => "model/vrml",
  190. "css" => "text/css",
  191. "html" => "text/html",
  192. "htm" => "text/html",
  193. "asc" => "text/plain",
  194. "txt" => "text/plain",
  195. "rtx" => "text/richtext",
  196. "rtf" => "text/rtf",
  197. "sgml" => "text/sgml",
  198. "sgm" => "text/sgml",
  199. "tsv" => "text/tab-seperated-values",
  200. "wml" => "text/vnd.wap.wml",
  201. "wmls" => "text/vnd.wap.wmlscript",
  202. "etx" => "text/x-setext",
  203. "xml" => "text/xml",
  204. "xsl" => "text/xml",
  205. "mpeg" => "video/mpeg",
  206. "mpg" => "video/mpeg",
  207. "mpe" => "video/mpeg",
  208. "mp4" => "video/mp4",
  209. "qt" => "video/quicktime",
  210. "mov" => "video/quicktime",
  211. "mxu" => "video/vnd.mpegurl",
  212. "avi" => "video/x-msvideo",
  213. "movie" => "video/x-sgi-movie",
  214. "ice" => "x-conference-xcooltalk"
  215. );
  216. }
  217. }
  218. ?>