PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/validator/sfValidatedFile.class.php

https://github.com/bheneka/gitta
PHP | 657 lines | 516 code | 28 blank | 113 comment | 13 complexity | 41f8e38166c6157ce05e244521b17f8d MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfValidatedFile represents a validated uploaded file.
  11. *
  12. * @package symfony
  13. * @subpackage validator
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id$
  16. */
  17. class sfValidatedFile
  18. {
  19. protected
  20. $originalName = '',
  21. $tempName = '',
  22. $savedName = null,
  23. $type = '',
  24. $size = 0,
  25. $path = null;
  26. /**
  27. * Constructor.
  28. *
  29. * @param string $originalName The original file name
  30. * @param string $type The file content type
  31. * @param string $tempName The absolute temporary path to the file
  32. * @param int $size The file size (in bytes)
  33. * @param string $path The path to save the file (optional).
  34. */
  35. public function __construct($originalName, $type, $tempName, $size, $path = null)
  36. {
  37. $this->originalName = $originalName;
  38. $this->tempName = $tempName;
  39. $this->type = $type;
  40. $this->size = $size;
  41. $this->path = $path;
  42. }
  43. /**
  44. * Returns the name of the saved file.
  45. */
  46. public function __toString()
  47. {
  48. return null === $this->savedName ? '' : $this->savedName;
  49. }
  50. /**
  51. * Saves the uploaded file.
  52. *
  53. * This method can throw exceptions if there is a problem when saving the file.
  54. *
  55. * If you don't pass a file name, it will be generated by the generateFilename method.
  56. * This will only work if you have passed a path when initializing this instance.
  57. *
  58. * @param string $file The file path to save the file
  59. * @param int $fileMode The octal mode to use for the new file
  60. * @param bool $create Indicates that we should make the directory before moving the file
  61. * @param int $dirMode The octal mode to use when creating the directory
  62. *
  63. * @return string The filename without the $this->path prefix
  64. *
  65. * @throws Exception
  66. */
  67. public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
  68. {
  69. if (null === $file)
  70. {
  71. $file = $this->generateFilename();
  72. }
  73. if ($file[0] != '/' && $file[0] != '\\' && !(strlen($file) > 3 && ctype_alpha($file[0]) && $file[1] == ':' && ($file[2] == '\\' || $file[2] == '/')))
  74. {
  75. if (null === $this->path)
  76. {
  77. throw new RuntimeException('You must give a "path" when you give a relative file name.');
  78. }
  79. $file = $this->path.DIRECTORY_SEPARATOR.$file;
  80. }
  81. // get our directory path from the destination filename
  82. $directory = dirname($file);
  83. if (!is_readable($directory))
  84. {
  85. if ($create && !@mkdir($directory, $dirMode, true))
  86. {
  87. // failed to create the directory
  88. throw new Exception(sprintf('Failed to create file upload directory "%s".', $directory));
  89. }
  90. // chmod the directory since it doesn't seem to work on recursive paths
  91. chmod($directory, $dirMode);
  92. }
  93. if (!is_dir($directory))
  94. {
  95. // the directory path exists but it's not a directory
  96. throw new Exception(sprintf('File upload path "%s" exists, but is not a directory.', $directory));
  97. }
  98. if (!is_writable($directory))
  99. {
  100. // the directory isn't writable
  101. throw new Exception(sprintf('File upload path "%s" is not writable.', $directory));
  102. }
  103. // copy the temp file to the destination file
  104. copy($this->getTempName(), $file);
  105. // chmod our file
  106. chmod($file, $fileMode);
  107. $this->savedName = $file;
  108. return null === $this->path ? $file : str_replace($this->path.DIRECTORY_SEPARATOR, '', $file);
  109. }
  110. /**
  111. * Generates a random filename for the current file.
  112. *
  113. * @return string A random name to represent the current file
  114. */
  115. public function generateFilename()
  116. {
  117. return sha1($this->getOriginalName().rand(11111, 99999)).$this->getExtension($this->getOriginalExtension());
  118. }
  119. /**
  120. * Returns the path to use when saving a file with a relative filename.
  121. *
  122. * @return string The path to use when saving a file with a relative filename
  123. */
  124. public function getPath()
  125. {
  126. return $this->path;
  127. }
  128. /**
  129. * Returns the file extension, based on the content type of the file.
  130. *
  131. * @param string $default The default extension to return if none was given
  132. *
  133. * @return string The extension (with the dot)
  134. */
  135. public function getExtension($default = '')
  136. {
  137. return $this->getExtensionFromType($this->type, $default);
  138. }
  139. /**
  140. * Returns the original uploaded file name extension.
  141. *
  142. * @param string $default The default extension to return if none was given
  143. *
  144. * @return string The extension of the uploaded name (with the dot)
  145. */
  146. public function getOriginalExtension($default = '')
  147. {
  148. return (false === $pos = strrpos($this->getOriginalName(), '.')) ? $default : substr($this->getOriginalName(), $pos);
  149. }
  150. /**
  151. * Returns true if the file has already been saved.
  152. *
  153. * @return Boolean true if the file has already been saved, false otherwise
  154. */
  155. public function isSaved()
  156. {
  157. return null !== $this->savedName;
  158. }
  159. /**
  160. * Returns the path where the file has been saved
  161. *
  162. * @return string The path where the file has been saved
  163. */
  164. public function getSavedName()
  165. {
  166. return $this->savedName;
  167. }
  168. /**
  169. * Returns the original file name.
  170. *
  171. * @return string The file name
  172. */
  173. public function getOriginalName()
  174. {
  175. return $this->originalName;
  176. }
  177. /**
  178. * Returns the absolute temporary path to the uploaded file.
  179. *
  180. * @return string The temporary path
  181. */
  182. public function getTempName()
  183. {
  184. return $this->tempName;
  185. }
  186. /**
  187. * Returns the file content type.
  188. *
  189. * @return string The content type
  190. */
  191. public function getType()
  192. {
  193. return $this->type;
  194. }
  195. /**
  196. * Returns the size of the uploaded file.
  197. *
  198. * @return int The file size
  199. */
  200. public function getSize()
  201. {
  202. return $this->size;
  203. }
  204. /**
  205. * Returns the extension associated with the given content type.
  206. *
  207. * @param string $type The content type
  208. * @param string $default The default extension to use
  209. *
  210. * @return string The extension (with the dot)
  211. */
  212. protected function getExtensionFromType($type, $default = '')
  213. {
  214. static $extensions = array(
  215. 'application/andrew-inset' => 'ez',
  216. 'application/appledouble' => 'base64',
  217. 'application/applefile' => 'base64',
  218. 'application/commonground' => 'dp',
  219. 'application/cprplayer' => 'pqi',
  220. 'application/dsptype' => 'tsp',
  221. 'application/excel' => 'xls',
  222. 'application/font-tdpfr' => 'pfr',
  223. 'application/futuresplash' => 'spl',
  224. 'application/hstu' => 'stk',
  225. 'application/hyperstudio' => 'stk',
  226. 'application/javascript' => 'js',
  227. 'application/mac-binhex40' => 'hqx',
  228. 'application/mac-compactpro' => 'cpt',
  229. 'application/mbed' => 'mbd',
  230. 'application/mirage' => 'mfp',
  231. 'application/msword' => 'doc',
  232. 'application/ocsp-request' => 'orq',
  233. 'application/ocsp-response' => 'ors',
  234. 'application/octet-stream' => 'bin',
  235. 'application/oda' => 'oda',
  236. 'application/ogg' => 'ogg',
  237. 'application/pdf' => 'pdf',
  238. 'application/x-pdf' => 'pdf',
  239. 'application/pgp-encrypted' => '7bit',
  240. 'application/pgp-keys' => '7bit',
  241. 'application/pgp-signature' => 'sig',
  242. 'application/pkcs10' => 'p10',
  243. 'application/pkcs7-mime' => 'p7m',
  244. 'application/pkcs7-signature' => 'p7s',
  245. 'application/pkix-cert' => 'cer',
  246. 'application/pkix-crl' => 'crl',
  247. 'application/pkix-pkipath' => 'pkipath',
  248. 'application/pkixcmp' => 'pki',
  249. 'application/postscript' => 'ps',
  250. 'application/presentations' => 'shw',
  251. 'application/prs.cww' => 'cw',
  252. 'application/prs.nprend' => 'rnd',
  253. 'application/quest' => 'qrt',
  254. 'application/rtf' => 'rtf',
  255. 'application/sgml-open-catalog' => 'soc',
  256. 'application/sieve' => 'siv',
  257. 'application/smil' => 'smi',
  258. 'application/toolbook' => 'tbk',
  259. 'application/vnd.3gpp.pic-bw-large' => 'plb',
  260. 'application/vnd.3gpp.pic-bw-small' => 'psb',
  261. 'application/vnd.3gpp.pic-bw-var' => 'pvb',
  262. 'application/vnd.3gpp.sms' => 'sms',
  263. 'application/vnd.acucorp' => 'atc',
  264. 'application/vnd.adobe.xfdf' => 'xfdf',
  265. 'application/vnd.amiga.amu' => 'ami',
  266. 'application/vnd.blueice.multipass' => 'mpm',
  267. 'application/vnd.cinderella' => 'cdy',
  268. 'application/vnd.cosmocaller' => 'cmc',
  269. 'application/vnd.criticaltools.wbs+xml' => 'wbs',
  270. 'application/vnd.curl' => 'curl',
  271. 'application/vnd.data-vision.rdz' => 'rdz',
  272. 'application/vnd.dreamfactory' => 'dfac',
  273. 'application/vnd.fsc.weblauch' => 'fsc',
  274. 'application/vnd.genomatix.tuxedo' => 'txd',
  275. 'application/vnd.hbci' => 'hbci',
  276. 'application/vnd.hhe.lesson-player' => 'les',
  277. 'application/vnd.hp-hpgl' => 'plt',
  278. 'application/vnd.ibm.electronic-media' => 'emm',
  279. 'application/vnd.ibm.rights-management' => 'irm',
  280. 'application/vnd.ibm.secure-container' => 'sc',
  281. 'application/vnd.ipunplugged.rcprofile' => 'rcprofile',
  282. 'application/vnd.irepository.package+xml' => 'irp',
  283. 'application/vnd.jisp' => 'jisp',
  284. 'application/vnd.kde.karbon' => 'karbon',
  285. 'application/vnd.kde.kchart' => 'chrt',
  286. 'application/vnd.kde.kformula' => 'kfo',
  287. 'application/vnd.kde.kivio' => 'flw',
  288. 'application/vnd.kde.kontour' => 'kon',
  289. 'application/vnd.kde.kpresenter' => 'kpr',
  290. 'application/vnd.kde.kspread' => 'ksp',
  291. 'application/vnd.kde.kword' => 'kwd',
  292. 'application/vnd.kenameapp' => 'htke',
  293. 'application/vnd.kidspiration' => 'kia',
  294. 'application/vnd.kinar' => 'kne',
  295. 'application/vnd.llamagraphics.life-balance.desktop' => 'lbd',
  296. 'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe',
  297. 'application/vnd.lotus-1-2-3' => 'wks',
  298. 'application/vnd.mcd' => 'mcd',
  299. 'application/vnd.mfmp' => 'mfm',
  300. 'application/vnd.micrografx.flo' => 'flo',
  301. 'application/vnd.micrografx.igx' => 'igx',
  302. 'application/vnd.mif' => 'mif',
  303. 'application/vnd.mophun.application' => 'mpn',
  304. 'application/vnd.mophun.certificate' => 'mpc',
  305. 'application/vnd.mozilla.xul+xml' => 'xul',
  306. 'application/vnd.ms-artgalry' => 'cil',
  307. 'application/vnd.ms-asf' => 'asf',
  308. 'application/vnd.ms-excel' => 'xls',
  309. 'application/vnd.ms-excel.sheet.macroenabled.12' => 'xlsm',
  310. 'application/vnd.ms-lrm' => 'lrm',
  311. 'application/vnd.ms-powerpoint' => 'ppt',
  312. 'application/vnd.ms-project' => 'mpp',
  313. 'application/vnd.ms-tnef' => 'base64',
  314. 'application/vnd.ms-works' => 'base64',
  315. 'application/vnd.ms-wpl' => 'wpl',
  316. 'application/vnd.mseq' => 'mseq',
  317. 'application/vnd.nervana' => 'ent',
  318. 'application/vnd.nokia.radio-preset' => 'rpst',
  319. 'application/vnd.nokia.radio-presets' => 'rpss',
  320. 'application/vnd.oasis.opendocument.text' => 'odt',
  321. 'application/vnd.oasis.opendocument.text-template' => 'ott',
  322. 'application/vnd.oasis.opendocument.text-web' => 'oth',
  323. 'application/vnd.oasis.opendocument.text-master' => 'odm',
  324. 'application/vnd.oasis.opendocument.graphics' => 'odg',
  325. 'application/vnd.oasis.opendocument.graphics-template' => 'otg',
  326. 'application/vnd.oasis.opendocument.presentation' => 'odp',
  327. 'application/vnd.oasis.opendocument.presentation-template' => 'otp',
  328. 'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
  329. 'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
  330. 'application/vnd.oasis.opendocument.chart' => 'odc',
  331. 'application/vnd.oasis.opendocument.formula' => 'odf',
  332. 'application/vnd.oasis.opendocument.database' => 'odb',
  333. 'application/vnd.oasis.opendocument.image' => 'odi',
  334. 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
  335. 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx',
  336. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
  337. 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
  338. 'application/vnd.palm' => 'prc',
  339. 'application/vnd.picsel' => 'efif',
  340. 'application/vnd.pvi.ptid1' => 'pti',
  341. 'application/vnd.quark.quarkxpress' => 'qxd',
  342. 'application/vnd.sealed.doc' => 'sdoc',
  343. 'application/vnd.sealed.eml' => 'seml',
  344. 'application/vnd.sealed.mht' => 'smht',
  345. 'application/vnd.sealed.ppt' => 'sppt',
  346. 'application/vnd.sealed.xls' => 'sxls',
  347. 'application/vnd.sealedmedia.softseal.html' => 'stml',
  348. 'application/vnd.sealedmedia.softseal.pdf' => 'spdf',
  349. 'application/vnd.seemail' => 'see',
  350. 'application/vnd.smaf' => 'mmf',
  351. 'application/vnd.sun.xml.calc' => 'sxc',
  352. 'application/vnd.sun.xml.calc.template' => 'stc',
  353. 'application/vnd.sun.xml.draw' => 'sxd',
  354. 'application/vnd.sun.xml.draw.template' => 'std',
  355. 'application/vnd.sun.xml.impress' => 'sxi',
  356. 'application/vnd.sun.xml.impress.template' => 'sti',
  357. 'application/vnd.sun.xml.math' => 'sxm',
  358. 'application/vnd.sun.xml.writer' => 'sxw',
  359. 'application/vnd.sun.xml.writer.global' => 'sxg',
  360. 'application/vnd.sun.xml.writer.template' => 'stw',
  361. 'application/vnd.sus-calendar' => 'sus',
  362. 'application/vnd.vidsoft.vidconference' => 'vsc',
  363. 'application/vnd.visio' => 'vsd',
  364. 'application/vnd.visionary' => 'vis',
  365. 'application/vnd.wap.sic' => 'sic',
  366. 'application/vnd.wap.slc' => 'slc',
  367. 'application/vnd.wap.wbxml' => 'wbxml',
  368. 'application/vnd.wap.wmlc' => 'wmlc',
  369. 'application/vnd.wap.wmlscriptc' => 'wmlsc',
  370. 'application/vnd.webturbo' => 'wtb',
  371. 'application/vnd.wordperfect' => 'wpd',
  372. 'application/vnd.wqd' => 'wqd',
  373. 'application/vnd.wv.csp+wbxml' => 'wv',
  374. 'application/vnd.wv.csp+xml' => '8bit',
  375. 'application/vnd.wv.ssp+xml' => '8bit',
  376. 'application/vnd.yamaha.hv-dic' => 'hvd',
  377. 'application/vnd.yamaha.hv-script' => 'hvs',
  378. 'application/vnd.yamaha.hv-voice' => 'hvp',
  379. 'application/vnd.yamaha.smaf-audio' => 'saf',
  380. 'application/vnd.yamaha.smaf-phrase' => 'spf',
  381. 'application/vocaltec-media-desc' => 'vmd',
  382. 'application/vocaltec-media-file' => 'vmf',
  383. 'application/vocaltec-talker' => 'vtk',
  384. 'application/watcherinfo+xml' => 'wif',
  385. 'application/wordperfect5.1' => 'wp5',
  386. 'application/x-123' => 'wk',
  387. 'application/x-7th_level_event' => '7ls',
  388. 'application/x-authorware-bin' => 'aab',
  389. 'application/x-authorware-map' => 'aam',
  390. 'application/x-authorware-seg' => 'aas',
  391. 'application/x-bcpio' => 'bcpio',
  392. 'application/x-bleeper' => 'bleep',
  393. 'application/x-bzip2' => 'bz2',
  394. 'application/x-cdlink' => 'vcd',
  395. 'application/x-chat' => 'chat',
  396. 'application/x-chess-pgn' => 'pgn',
  397. 'application/x-compress' => 'z',
  398. 'application/x-cpio' => 'cpio',
  399. 'application/x-cprplayer' => 'pqf',
  400. 'application/x-csh' => 'csh',
  401. 'application/x-cu-seeme' => 'csm',
  402. 'application/x-cult3d-object' => 'co',
  403. 'application/x-debian-package' => 'deb',
  404. 'application/x-director' => 'dcr',
  405. 'application/x-dvi' => 'dvi',
  406. 'application/x-envoy' => 'evy',
  407. 'application/x-futuresplash' => 'spl',
  408. 'application/x-gtar' => 'gtar',
  409. 'application/x-gzip' => 'gz',
  410. 'application/x-hdf' => 'hdf',
  411. 'application/x-hep' => 'hep',
  412. 'application/x-html+ruby' => 'rhtml',
  413. 'application/x-httpd-miva' => 'mv',
  414. 'application/x-httpd-php' => 'phtml',
  415. 'application/x-ica' => 'ica',
  416. 'application/x-imagemap' => 'imagemap',
  417. 'application/x-ipix' => 'ipx',
  418. 'application/x-ipscript' => 'ips',
  419. 'application/x-java-archive' => 'jar',
  420. 'application/x-java-jnlp-file' => 'jnlp',
  421. 'application/x-java-serialized-object' => 'ser',
  422. 'application/x-java-vm' => 'class',
  423. 'application/x-javascript' => 'js',
  424. 'application/x-koan' => 'skp',
  425. 'application/x-latex' => 'latex',
  426. 'application/x-mac-compactpro' => 'cpt',
  427. 'application/x-maker' => 'frm',
  428. 'application/x-mathcad' => 'mcd',
  429. 'application/x-midi' => 'mid',
  430. 'application/x-mif' => 'mif',
  431. 'application/x-msaccess' => 'mda',
  432. 'application/x-msdos-program' => 'com',
  433. 'application/x-msdownload' => 'base64',
  434. 'application/x-msexcel' => 'xls',
  435. 'application/x-msword' => 'doc',
  436. 'application/x-netcdf' => 'nc',
  437. 'application/x-ns-proxy-autoconfig' => 'pac',
  438. 'application/x-pagemaker' => 'pm5',
  439. 'application/x-perl' => 'pl',
  440. 'application/x-pn-realmedia' => 'rp',
  441. 'application/x-python' => 'py',
  442. 'application/x-quicktimeplayer' => 'qtl',
  443. 'application/x-rar-compressed' => 'rar',
  444. 'application/x-ruby' => 'rb',
  445. 'application/x-sh' => 'sh',
  446. 'application/x-shar' => 'shar',
  447. 'application/x-shockwave-flash' => 'swf',
  448. 'application/x-sprite' => 'spr',
  449. 'application/x-spss' => 'sav',
  450. 'application/x-spt' => 'spt',
  451. 'application/x-stuffit' => 'sit',
  452. 'application/x-sv4cpio' => 'sv4cpio',
  453. 'application/x-sv4crc' => 'sv4crc',
  454. 'application/x-tar' => 'tar',
  455. 'application/x-tcl' => 'tcl',
  456. 'application/x-tex' => 'tex',
  457. 'application/x-texinfo' => 'texinfo',
  458. 'application/x-troff' => 't',
  459. 'application/x-troff-man' => 'man',
  460. 'application/x-troff-me' => 'me',
  461. 'application/x-troff-ms' => 'ms',
  462. 'application/x-twinvq' => 'vqf',
  463. 'application/x-twinvq-plugin' => 'vqe',
  464. 'application/x-ustar' => 'ustar',
  465. 'application/x-vmsbackup' => 'bck',
  466. 'application/x-wais-source' => 'src',
  467. 'application/x-wingz' => 'wz',
  468. 'application/x-word' => 'base64',
  469. 'application/x-wordperfect6.1' => 'wp6',
  470. 'application/x-x509-ca-cert' => 'crt',
  471. 'application/x-zip-compressed' => 'zip',
  472. 'application/xhtml+xml' => 'xhtml',
  473. 'application/zip' => 'zip',
  474. 'audio/3gpp' => '3gpp',
  475. 'audio/amr' => 'amr',
  476. 'audio/amr-wb' => 'awb',
  477. 'audio/basic' => 'au',
  478. 'audio/evrc' => 'evc',
  479. 'audio/l16' => 'l16',
  480. 'audio/midi' => 'mid',
  481. 'audio/mpeg' => 'mp3',
  482. 'audio/prs.sid' => 'sid',
  483. 'audio/qcelp' => 'qcp',
  484. 'audio/smv' => 'smv',
  485. 'audio/vnd.audiokoz' => 'koz',
  486. 'audio/vnd.digital-winds' => 'eol',
  487. 'audio/vnd.everad.plj' => 'plj',
  488. 'audio/vnd.lucent.voice' => 'lvp',
  489. 'audio/vnd.nokia.mobile-xmf' => 'mxmf',
  490. 'audio/vnd.nortel.vbk' => 'vbk',
  491. 'audio/vnd.nuera.ecelp4800' => 'ecelp4800',
  492. 'audio/vnd.nuera.ecelp7470' => 'ecelp7470',
  493. 'audio/vnd.nuera.ecelp9600' => 'ecelp9600',
  494. 'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3',
  495. 'audio/voxware' => 'vox',
  496. 'audio/x-aiff' => 'aif',
  497. 'audio/x-mid' => 'mid',
  498. 'audio/x-midi' => 'mid',
  499. 'audio/x-mpeg' => 'mp2',
  500. 'audio/x-mpegurl' => 'mpu',
  501. 'audio/x-pn-realaudio' => 'rm',
  502. 'audio/x-pn-realaudio-plugin' => 'rpm',
  503. 'audio/x-realaudio' => 'ra',
  504. 'audio/x-wav' => 'wav',
  505. 'chemical/x-csml' => 'csm',
  506. 'chemical/x-embl-dl-nucleotide' => 'emb',
  507. 'chemical/x-gaussian-cube' => 'cube',
  508. 'chemical/x-gaussian-input' => 'gau',
  509. 'chemical/x-jcamp-dx' => 'jdx',
  510. 'chemical/x-mdl-molfile' => 'mol',
  511. 'chemical/x-mdl-rxnfile' => 'rxn',
  512. 'chemical/x-mdl-tgf' => 'tgf',
  513. 'chemical/x-mopac-input' => 'mop',
  514. 'chemical/x-pdb' => 'pdb',
  515. 'chemical/x-rasmol' => 'scr',
  516. 'chemical/x-xyz' => 'xyz',
  517. 'drawing/dwf' => 'dwf',
  518. 'drawing/x-dwf' => 'dwf',
  519. 'i-world/i-vrml' => 'ivr',
  520. 'image/bmp' => 'bmp',
  521. 'image/cewavelet' => 'wif',
  522. 'image/cis-cod' => 'cod',
  523. 'image/fif' => 'fif',
  524. 'image/gif' => 'gif',
  525. 'image/ief' => 'ief',
  526. 'image/jp2' => 'jp2',
  527. 'image/jpeg' => 'jpg',
  528. 'image/jpm' => 'jpm',
  529. 'image/jpx' => 'jpf',
  530. 'image/pict' => 'pic',
  531. 'image/pjpeg' => 'jpg',
  532. 'image/png' => 'png',
  533. 'image/targa' => 'tga',
  534. 'image/tiff' => 'tif',
  535. 'image/vn-svf' => 'svf',
  536. 'image/vnd.dgn' => 'dgn',
  537. 'image/vnd.djvu' => 'djvu',
  538. 'image/vnd.dwg' => 'dwg',
  539. 'image/vnd.glocalgraphics.pgb' => 'pgb',
  540. 'image/vnd.microsoft.icon' => 'ico',
  541. 'image/vnd.ms-modi' => 'mdi',
  542. 'image/vnd.sealed.png' => 'spng',
  543. 'image/vnd.sealedmedia.softseal.gif' => 'sgif',
  544. 'image/vnd.sealedmedia.softseal.jpg' => 'sjpg',
  545. 'image/vnd.wap.wbmp' => 'wbmp',
  546. 'image/x-bmp' => 'bmp',
  547. 'image/x-cmu-raster' => 'ras',
  548. 'image/x-freehand' => 'fh4',
  549. 'image/x-ms-bmp' => 'bmp',
  550. 'image/x-png' => 'png',
  551. 'image/x-portable-anymap' => 'pnm',
  552. 'image/x-portable-bitmap' => 'pbm',
  553. 'image/x-portable-graymap' => 'pgm',
  554. 'image/x-portable-pixmap' => 'ppm',
  555. 'image/x-rgb' => 'rgb',
  556. 'image/x-xbitmap' => 'xbm',
  557. 'image/x-xpixmap' => 'xpm',
  558. 'image/x-xwindowdump' => 'xwd',
  559. 'message/external-body' => '8bit',
  560. 'message/news' => '8bit',
  561. 'message/partial' => '8bit',
  562. 'message/rfc822' => '8bit',
  563. 'model/iges' => 'igs',
  564. 'model/mesh' => 'msh',
  565. 'model/vnd.parasolid.transmit.binary' => 'x_b',
  566. 'model/vnd.parasolid.transmit.text' => 'x_t',
  567. 'model/vrml' => 'wrl',
  568. 'multipart/alternative' => '8bit',
  569. 'multipart/appledouble' => '8bit',
  570. 'multipart/digest' => '8bit',
  571. 'multipart/mixed' => '8bit',
  572. 'multipart/parallel' => '8bit',
  573. 'text/comma-separated-values' => 'csv',
  574. 'text/css' => 'css',
  575. 'text/html' => 'html',
  576. 'text/plain' => 'txt',
  577. 'text/prs.fallenstein.rst' => 'rst',
  578. 'text/richtext' => 'rtx',
  579. 'text/rtf' => 'rtf',
  580. 'text/sgml' => 'sgml',
  581. 'text/tab-separated-values' => 'tsv',
  582. 'text/vnd.net2phone.commcenter.command' => 'ccc',
  583. 'text/vnd.sun.j2me.app-descriptor' => 'jad',
  584. 'text/vnd.wap.si' => 'si',
  585. 'text/vnd.wap.sl' => 'sl',
  586. 'text/vnd.wap.wml' => 'wml',
  587. 'text/vnd.wap.wmlscript' => 'wmls',
  588. 'text/x-hdml' => 'hdml',
  589. 'text/x-setext' => 'etx',
  590. 'text/x-sgml' => 'sgml',
  591. 'text/x-speech' => 'talk',
  592. 'text/x-vcalendar' => 'vcs',
  593. 'text/x-vcard' => 'vcf',
  594. 'text/xml' => 'xml',
  595. 'ulead/vrml' => 'uvr',
  596. 'video/3gpp' => '3gp',
  597. 'video/dl' => 'dl',
  598. 'video/gl' => 'gl',
  599. 'video/mj2' => 'mj2',
  600. 'video/mpeg' => 'mpeg',
  601. 'video/quicktime' => 'mov',
  602. 'video/vdo' => 'vdo',
  603. 'video/vivo' => 'viv',
  604. 'video/vnd.fvt' => 'fvt',
  605. 'video/vnd.mpegurl' => 'mxu',
  606. 'video/vnd.nokia.interleaved-multimedia' => 'nim',
  607. 'video/vnd.objectvideo' => 'mp4',
  608. 'video/vnd.sealed.mpeg1' => 's11',
  609. 'video/vnd.sealed.mpeg4' => 'smpg',
  610. 'video/vnd.sealed.swf' => 'sswf',
  611. 'video/vnd.sealedmedia.softseal.mov' => 'smov',
  612. 'video/vnd.vivo' => 'vivo',
  613. 'video/x-fli' => 'fli',
  614. 'video/x-ms-asf' => 'asf',
  615. 'video/x-ms-wmv' => 'wmv',
  616. 'video/x-msvideo' => 'avi',
  617. 'video/x-sgi-movie' => 'movie',
  618. 'x-chemical/x-pdb' => 'pdb',
  619. 'x-chemical/x-xyz' => 'xyz',
  620. 'x-conference/x-cooltalk' => 'ice',
  621. 'x-drawing/dwf' => 'dwf',
  622. 'x-world/x-d96' => 'd',
  623. 'x-world/x-svr' => 'svr',
  624. 'x-world/x-vream' => 'vrw',
  625. 'x-world/x-vrml' => 'wrl',
  626. );
  627. return !$type ? $default : (isset($extensions[$type]) ? '.'.$extensions[$type] : $default);
  628. }
  629. }