Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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