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

Debug toolbar