Development

/branches/1.2/lib/validator/sfValidatorFile.class.php

You must first sign up to be able to contribute.

root/branches/1.2/lib/validator/sfValidatorFile.class.php

Revision 26264, 31.8 kB (checked in by fabien, 4 years ago)

[1.2, 1.3, 1.4] fixed PHPDoc (closes #7983)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
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  * sfValidatorFile validates an uploaded file.
13  *
14  * @package    symfony
15  * @subpackage validator
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfValidatorFile extends sfValidatorBase
20 {
21   /**
22    * Configures the current validator.
23    *
24    * Available options:
25    *
26    *  * max_size:             The maximum file size
27    *  * mime_types:           Allowed mime types array or category (available categories: web_images)
28    *  * mime_type_guessers:   An array of mime type guesser PHP callables (must return the mime type or null)
29    *  * mime_categories:      An array of mime type categories (web_images is defined by default)
30    *  * path:                 The path where to save the file - as used by the sfValidatedFile class (optional)
31    *  * validated_file_class: Name of the class that manages the cleaned uploaded file (optional)
32    *
33    * There are 3 built-in mime type guessers:
34    *
35    *  * guessFromFileinfo:        Uses the finfo_open() function (from the Fileinfo PECL extension)
36    *  * guessFromMimeContentType: Uses the mime_content_type() function (deprecated)
37    *  * guessFromFileBinary:      Uses the file binary (only works on *nix system)
38    *
39    * Available error codes:
40    *
41    *  * max_size
42    *  * mime_types
43    *  * partial
44    *  * no_tmp_dir
45    *  * cant_write
46    *  * extension
47    *
48    * @param array $options   An array of options
49    * @param array $messages  An array of error messages
50    *
51    * @see sfValidatorBase
52    */
53   protected function configure($options = array(), $messages = array())
54   {
55     if (!ini_get('file_uploads'))
56     {
57       throw new LogicException(sprintf('Unable to use a file validator as "file_uploads" is disabled in your php.ini file (%s)', get_cfg_var('cfg_file_path')));
58     }
59
60     $this->addOption('max_size');
61     $this->addOption('mime_types');
62     $this->addOption('mime_type_guessers', array(
63       array($this, 'guessFromFileinfo'),
64       array($this, 'guessFromMimeContentType'),
65       array($this, 'guessFromFileBinary'),
66     ));
67     $this->addOption('mime_categories', array(
68       'web_images' => array(
69         'image/jpeg',
70         'image/pjpeg',
71         'image/png',
72         'image/x-png',
73         'image/gif',
74     )));
75     $this->addOption('validated_file_class', 'sfValidatedFile');
76     $this->addOption('path', null);
77
78     $this->addMessage('max_size', 'File is too large (maximum is %max_size% bytes).');
79     $this->addMessage('mime_types', 'Invalid mime type (%mime_type%).');
80     $this->addMessage('partial', 'The uploaded file was only partially uploaded.');
81     $this->addMessage('no_tmp_dir', 'Missing a temporary folder.');
82     $this->addMessage('cant_write', 'Failed to write file to disk.');
83     $this->addMessage('extension', 'File upload stopped by extension.');
84   }
85
86   /**
87    * This validator always returns a sfValidatedFile object.
88    *
89    * The input value must be an array with the following keys:
90    *
91    *  * tmp_name: The absolute temporary path to the file
92    *  * name:     The original file name (optional)
93    *  * type:     The file content type (optional)
94    *  * error:    The error code (optional)
95    *  * size:     The file size in bytes (optional)
96    *
97    * @see sfValidatorBase
98    */
99   protected function doClean($value)
100   {
101     if (!is_array($value) || !isset($value['tmp_name']))
102     {
103       throw new sfValidatorError($this, 'invalid', array('value' => (string) $value));
104     }
105
106     if (!isset($value['name']))
107     {
108       $value['name'] = '';
109     }
110
111     if (!isset($value['error']))
112     {
113       $value['error'] = UPLOAD_ERR_OK;
114     }
115
116     if (!isset($value['size']))
117     {
118       $value['size'] = filesize($value['tmp_name']);
119     }
120
121     if (!isset($value['type']))
122     {
123       $value['type'] = 'application/octet-stream';
124     }
125
126     switch ($value['error'])
127     {
128       case UPLOAD_ERR_INI_SIZE:
129         $max = ini_get('upload_max_filesize');
130         if ($this->getOption('max_size'))
131         {
132           $max = min($max, $this->getOption('max_size'));
133         }
134         throw new sfValidatorError($this, 'max_size', array('max_size' => $max, 'size' => (int) $value['size']));
135       case UPLOAD_ERR_FORM_SIZE:
136         throw new sfValidatorError($this, 'max_size', array('max_size' => 0, 'size' => (int) $value['size']));
137       case UPLOAD_ERR_PARTIAL:
138         throw new sfValidatorError($this, 'partial');
139       case UPLOAD_ERR_NO_TMP_DIR:
140         throw new sfValidatorError($this, 'no_tmp_dir');
141       case UPLOAD_ERR_CANT_WRITE:
142         throw new sfValidatorError($this, 'cant_write');
143       case UPLOAD_ERR_EXTENSION:
144         throw new sfValidatorError($this, 'extension');
145     }
146
147     // check file size
148     if ($this->hasOption('max_size') && $this->getOption('max_size') < (int) $value['size'])
149     {
150       throw new sfValidatorError($this, 'max_size', array('max_size' => $this->getOption('max_size'), 'size' => (int) $value['size']));
151     }
152
153     $mimeType = $this->getMimeType((string) $value['tmp_name'], (string) $value['type']);
154
155     // check mime type
156     if ($this->hasOption('mime_types'))
157     {
158       $mimeTypes = is_array($this->getOption('mime_types')) ? $this->getOption('mime_types') : $this->getMimeTypesFromCategory($this->getOption('mime_types'));
159       if (!in_array($mimeType, $mimeTypes))
160       {
161         throw new sfValidatorError($this, 'mime_types', array('mime_types' => $mimeTypes, 'mime_type' => $mimeType));
162       }
163     }
164
165     $class = $this->getOption('validated_file_class');
166
167     return new $class($value['name'], $mimeType, $value['tmp_name'], $value['size'], $this->getOption('path'));
168   }
169
170   /**
171    * Returns the mime type of a file.
172    *
173    * This methods call each mime_type_guessers option callables to
174    * guess the mime type.
175    *
176    * @param  string $file      The absolute path of a file
177    * @param  string $fallback  The default mime type to return if not guessable
178    *
179    * @return string The mime type of the file (fallback is returned if not guessable)
180    */
181   protected function getMimeType($file, $fallback)
182   {
183     foreach ($this->getOption('mime_type_guessers') as $method)
184     {
185       $type = call_user_func($method, $file);
186
187       if (!is_null($type) && $type !== false)
188       {
189         return $type;
190       }
191     }
192
193     return $fallback;
194   }
195
196   /**
197    * Guess the file mime type with PECL Fileinfo extension
198    *
199    * @param  string $file  The absolute path of a file
200    *
201    * @return string The mime type of the file (null if not guessable)
202    */
203   protected function guessFromFileinfo($file)
204   {
205     if (!function_exists('finfo_open') || !is_readable($file))
206     {
207       return null;
208     }
209
210     if (!$finfo = new finfo(FILEINFO_MIME))
211     {
212       return null;
213     }
214
215     $type = $finfo->file($file);
216
217     // remove charset (added as of PHP 5.3)
218     if (false !== $pos = strpos($type, ';'))
219     {
220       $type = substr($type, 0, $pos);
221     }
222
223     return $type;
224   }
225
226   /**
227    * Guess the file mime type with mime_content_type function (deprecated)
228    *
229    * @param  string $file  The absolute path of a file
230    *
231    * @return string The mime type of the file (null if not guessable)
232    */
233   protected function guessFromMimeContentType($file)
234   {
235     if (!function_exists('mime_content_type') || !is_readable($file))
236     {
237       return null;
238     }
239
240     return mime_content_type($file);
241   }
242
243   /**
244    * Guess the file mime type with the file binary (only available on *nix)
245    *
246    * @param  string $file  The absolute path of a file
247    *
248    * @return string The mime type of the file (null if not guessable)
249    */
250   protected function guessFromFileBinary($file)
251   {
252     ob_start();
253     //need to use --mime instead of -i. see #6641
254     passthru(sprintf('file -b --mime %s 2>/dev/null', escapeshellarg($file)), $return);
255     if ($return > 0)
256     {
257       ob_end_clean();
258
259       return null;
260     }
261     $type = trim(ob_get_clean());
262
263     if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-]+)#i', $type, $match))
264     {
265       // it's not a type, but an error message
266       return null;
267     }
268
269     return $match[1];
270   }
271
272   protected function getMimeTypesFromCategory($category)
273   {
274     $categories = $this->getOption('mime_categories');
275
276     if (!isset($categories[$category]))
277     {
278       throw new InvalidArgumentException(sprintf('Invalid mime type category "%s".', $category));
279     }
280
281     return $categories[$category];
282   }
283
284   /**
285    * @see sfValidatorBase
286    */
287   protected function isEmpty($value)
288   {
289     // empty if the value is not an array
290     // or if the value comes from PHP with an error of UPLOAD_ERR_NO_FILE
291     return
292       (!is_array($value))
293         ||
294       (is_array($value) && isset($value['error']) && UPLOAD_ERR_NO_FILE === $value['error']);
295   }
296 }
297
298 /**
299  * sfValidatedFile represents a validated uploaded file.
300  *
301  * @package    symfony
302  * @subpackage validator
303  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
304  * @version    SVN: $Id$
305  */
306 class sfValidatedFile
307 {
308   protected
309     $originalName = '',
310     $tempName     = '',
311     $savedName    = null,
312     $type         = '',
313     $size         = 0,
314     $path         = null;
315
316   /**
317    * Constructor.
318    *
319    * @param string $originalName  The original file name
320    * @param string $type          The file content type
321    * @param string $tempName      The absolute temporary path to the file
322    * @param int    $size          The file size (in bytes)
323    * @param string $path          The path to save the file (optional).
324    */
325   public function __construct($originalName, $type, $tempName, $size, $path = null)
326   {
327     $this->originalName = $originalName;
328     $this->tempName = $tempName;
329     $this->type = $type;
330     $this->size = $size;
331     $this->path = $path;
332   }
333
334   /**
335    * Returns the name of the saved file.
336    */
337   public function __toString()
338   {
339     return is_null($this->savedName) ? '' : $this->savedName;
340   }
341
342   /**
343    * Saves the uploaded file.
344    *
345    * This method can throw exceptions if there is a problem when saving the file.
346    *
347    * If you don't pass a file name, it will be generated by the generateFilename method.
348    * This will only work if you have passed a path when initializing this instance.
349    *
350    * @param  string $file      The file path to save the file
351    * @param  int    $fileMode  The octal mode to use for the new file
352    * @param  bool   $create    Indicates that we should make the directory before moving the file
353    * @param  int    $dirMode   The octal mode to use when creating the directory
354    *
355    * @return string The filename without the $this->path prefix
356    *
357    * @throws Exception
358    */
359   public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
360   {
361     if (is_null($file))
362     {
363       $file = $this->generateFilename();
364     }
365
366     if ($file[0] != '/' && $file[0] != '\\' && !(strlen($file) > 3 && ctype_alpha($file[0]) && $file[1] == ':' && ($file[2] == '\\' || $file[2] == '/')))
367     {
368       if (is_null($this->path))
369       {
370         throw new RuntimeException('You must give a "path" when you give a relative file name.');
371       }
372
373       $file = $this->path.DIRECTORY_SEPARATOR.$file;
374     }
375
376     // get our directory path from the destination filename
377     $directory = dirname($file);
378
379     if (!is_readable($directory))
380     {
381       if ($create && !@mkdir($directory, $dirMode, true))
382       {
383         // failed to create the directory
384         throw new Exception(sprintf('Failed to create file upload directory "%s".', $directory));
385       }
386
387       // chmod the directory since it doesn't seem to work on recursive paths
388       chmod($directory, $dirMode);
389     }
390
391     if (!is_dir($directory))
392     {
393       // the directory path exists but it's not a directory
394       throw new Exception(sprintf('File upload path "%s" exists, but is not a directory.', $directory));
395     }
396
397     if (!is_writable($directory))
398     {
399       // the directory isn't writable
400       throw new Exception(sprintf('File upload path "%s" is not writable.', $directory));
401     }
402
403     // copy the temp file to the destination file
404     copy($this->getTempName(), $file);
405
406     // chmod our file
407     chmod($file, $fileMode);
408
409     $this->savedName = $file;
410
411     return is_null($this->path) ? $file : str_replace($this->path.DIRECTORY_SEPARATOR, '', $file);
412   }
413
414   /**
415    * Generates a random filename for the current file.
416    *
417    * @return string A random name to represent the current file
418    */
419   public function generateFilename()
420   {
421     return sha1($this->getOriginalName().rand(11111, 99999)).$this->getExtension($this->getOriginalExtension());
422   }
423
424   /**
425    * Returns the path to use when saving a file with a relative filename.
426    *
427    * @return string The path to use when saving a file with a relative filename
428    */
429   public function getPath()
430   {
431     return $this->path;
432   }
433
434   /**
435    * Returns the file extension, based on the content type of the file.
436    *
437    * @param  string $default  The default extension to return if none was given
438    *
439    * @return string The extension (with the dot)
440    */
441   public function getExtension($default = '')
442   {
443     return $this->getExtensionFromType($this->type, $default);
444   }
445
446   /**
447    * Returns the original uploaded file name extension.
448    *
449    * @param  string $default  The default extension to return if none was given
450    *
451    * @return string The extension of the uploaded name (with the dot)
452    */
453   public function getOriginalExtension($default = '')
454   {
455     return (false === $pos = strrpos($this->getOriginalName(), '.')) ? $default : substr($this->getOriginalName(), $pos);
456   }
457
458   /**
459    * Returns true if the file has already been saved.
460    *
461    * @return Boolean true if the file has already been saved, false otherwise
462    */
463   public function isSaved()
464   {
465     return !is_null($this->savedName);
466   }
467
468   /**
469    * Returns the path where the file has been saved
470    *
471    * @return string The path where the file has been saved
472    */
473   public function getSavedName()
474   {
475     return $this->savedName;
476   }
477
478   /**
479    * Returns the original file name.
480    *
481    * @return string The file name
482    */
483   public function getOriginalName()
484   {
485     return $this->originalName;
486   }
487
488   /**
489    * Returns the absolute temporary path to the uploaded file.
490    *
491    * @return string The temporary path
492    */
493   public function getTempName()
494   {
495     return $this->tempName;
496   }
497
498   /**
499    * Returns the file content type.
500    *
501    * @return string The content type
502    */
503   public function getType()
504   {
505     return $this->type;
506   }
507
508   /**
509    * Returns the size of the uploaded file.
510    *
511    * @return int The file size
512    */
513   public function getSize()
514   {
515     return $this->size;
516   }
517
518   /**
519    * Returns the extension associated with the given content type.
520    *
521    * @param  string $type     The content type
522    * @param  string $default  The default extension to use
523    *
524    * @return string The extension (with the dot)
525    */
526   protected function getExtensionFromType($type, $default = '')
527   {
528     static $extensions = array(
529       'application/andrew-inset' => 'ez',
530       'application/appledouble' => 'base64',
531       'application/applefile' => 'base64',
532       'application/commonground' => 'dp',
533       'application/cprplayer' => 'pqi',
534       'application/dsptype' => 'tsp',
535       'application/excel' => 'xls',
536       'application/font-tdpfr' => 'pfr',
537       'application/futuresplash' => 'spl',
538       'application/hstu' => 'stk',
539       'application/hyperstudio' => 'stk',
540       'application/javascript' => 'js',
541       'application/mac-binhex40' => 'hqx',
542       'application/mac-compactpro' => 'cpt',
543       'application/mbed' => 'mbd',
544       'application/mirage' => 'mfp',
545       'application/msword' => 'doc',
546       'application/ocsp-request' => 'orq',
547       'application/ocsp-response' => 'ors',
548       'application/octet-stream' => 'bin',
549       'application/oda' => 'oda',
550       'application/ogg' => 'ogg',
551       'application/pdf' => 'pdf',
552       'application/x-pdf' => 'pdf',
553       'application/pgp-encrypted' => '7bit',
554       'application/pgp-keys' => '7bit',
555       'application/pgp-signature' => 'sig',
556       'application/pkcs10' => 'p10',
557       'application/pkcs7-mime' => 'p7m',
558       'application/pkcs7-signature' => 'p7s',
559       'application/pkix-cert' => 'cer',
560       'application/pkix-crl' => 'crl',
561       'application/pkix-pkipath' => 'pkipath',
562       'application/pkixcmp' => 'pki',
563       'application/postscript' => 'ps',
564       'application/presentations' => 'shw',
565       'application/prs.cww' => 'cw',
566       'application/prs.nprend' => 'rnd',
567       'application/quest' => 'qrt',
568       'application/rtf' => 'rtf',
569       'application/sgml-open-catalog' => 'soc',
570       'application/sieve' => 'siv',
571       'application/smil' => 'smi',
572       'application/toolbook' => 'tbk',
573       'application/vnd.3gpp.pic-bw-large' => 'plb',
574       'application/vnd.3gpp.pic-bw-small' => 'psb',
575       'application/vnd.3gpp.pic-bw-var' => 'pvb',
576       'application/vnd.3gpp.sms' => 'sms',
577       'application/vnd.acucorp' => 'atc',
578       'application/vnd.adobe.xfdf' => 'xfdf',
579       'application/vnd.amiga.amu' => 'ami',
580       'application/vnd.blueice.multipass' => 'mpm',
581       'application/vnd.cinderella' => 'cdy',
582       'application/vnd.cosmocaller' => 'cmc',
583       'application/vnd.criticaltools.wbs+xml' => 'wbs',
584       'application/vnd.curl' => 'curl',
585       'application/vnd.data-vision.rdz' => 'rdz',
586       'application/vnd.dreamfactory' => 'dfac',
587       'application/vnd.fsc.weblauch' => 'fsc',
588       'application/vnd.genomatix.tuxedo' => 'txd',
589       'application/vnd.hbci' => 'hbci',
590       'application/vnd.hhe.lesson-player' => 'les',
591       'application/vnd.hp-hpgl' => 'plt',
592       'application/vnd.ibm.electronic-media' => 'emm',
593       'application/vnd.ibm.rights-management' => 'irm',
594       'application/vnd.ibm.secure-container' => 'sc',
595       'application/vnd.ipunplugged.rcprofile' => 'rcprofile',
596       'application/vnd.irepository.package+xml' => 'irp',
597       'application/vnd.jisp' => 'jisp',
598       'application/vnd.kde.karbon' => 'karbon',
599       'application/vnd.kde.kchart' => 'chrt',
600       'application/vnd.kde.kformula' => 'kfo',
601       'application/vnd.kde.kivio' => 'flw',
602       'application/vnd.kde.kontour' => 'kon',
603       'application/vnd.kde.kpresenter' => 'kpr',
604       'application/vnd.kde.kspread' => 'ksp',
605       'application/vnd.kde.kword' => 'kwd',
606       'application/vnd.kenameapp' => 'htke',
607       'application/vnd.kidspiration' => 'kia',
608       'application/vnd.kinar' => 'kne',
609       'application/vnd.llamagraphics.life-balance.desktop' => 'lbd',
610       'application/vnd.llamagraphics.life-balance.exchange+xml' => 'lbe',
611       'application/vnd.lotus-1-2-3' => 'wks',
612       'application/vnd.mcd' => 'mcd',
613       'application/vnd.mfmp' => 'mfm',
614       'application/vnd.micrografx.flo' => 'flo',
615       'application/vnd.micrografx.igx' => 'igx',
616       'application/vnd.mif' => 'mif',
617       'application/vnd.mophun.application' => 'mpn',
618       'application/vnd.mophun.certificate' => 'mpc',
619       'application/vnd.mozilla.xul+xml' => 'xul',
620       'application/vnd.ms-artgalry' => 'cil',
621       'application/vnd.ms-asf' => 'asf',
622       'application/vnd.ms-excel' => 'xls',
623       'application/vnd.ms-excel.sheet.macroEnabled.12' => 'xlsm',
624       'application/vnd.ms-lrm' => 'lrm',
625       'application/vnd.ms-powerpoint' => 'ppt',
626       'application/vnd.ms-project' => 'mpp',
627       'application/vnd.ms-tnef' => 'base64',
628       'application/vnd.ms-works' => 'base64',
629       'application/vnd.ms-wpl' => 'wpl',
630       'application/vnd.mseq' => 'mseq',
631       'application/vnd.nervana' => 'ent',
632       'application/vnd.nokia.radio-preset' => 'rpst',
633       'application/vnd.nokia.radio-presets' => 'rpss',
634       'application/vnd.oasis.opendocument.text' => 'odt',
635       'application/vnd.oasis.opendocument.text-template' => 'ott',
636       'application/vnd.oasis.opendocument.text-web' => 'oth',
637       'application/vnd.oasis.opendocument.text-master' => 'odm',
638       'application/vnd.oasis.opendocument.graphics' => 'odg',
639       'application/vnd.oasis.opendocument.graphics-template' => 'otg',
640       'application/vnd.oasis.opendocument.presentation' => 'odp',
641       'application/vnd.oasis.opendocument.presentation-template' => 'otp',
642       'application/vnd.oasis.opendocument.spreadsheet' => 'ods',
643       'application/vnd.oasis.opendocument.spreadsheet-template' => 'ots',
644       'application/vnd.oasis.opendocument.chart' => 'odc',
645       'application/vnd.oasis.opendocument.formula' => 'odf',
646       'application/vnd.oasis.opendocument.database' => 'odb',
647       'application/vnd.oasis.opendocument.image' => 'odi',
648       'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
649       'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'dotx',
650       'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
651       'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'pptx',
652       'application/vnd.palm' => 'prc',
653       'application/vnd.picsel' => 'efif',
654       'application/vnd.pvi.ptid1' => 'pti',
655       'application/vnd.quark.quarkxpress' => 'qxd',
656       'application/vnd.sealed.doc' => 'sdoc',
657       'application/vnd.sealed.eml' => 'seml',
658       'application/vnd.sealed.mht' => 'smht',
659       'application/vnd.sealed.ppt' => 'sppt',
660       'application/vnd.sealed.xls' => 'sxls',
661       'application/vnd.sealedmedia.softseal.html' => 'stml',
662       'application/vnd.sealedmedia.softseal.pdf' => 'spdf',
663       'application/vnd.seemail' => 'see',
664       'application/vnd.smaf' => 'mmf',
665       'application/vnd.sun.xml.calc' => 'sxc',
666       'application/vnd.sun.xml.calc.template' => 'stc',
667       'application/vnd.sun.xml.draw' => 'sxd',
668       'application/vnd.sun.xml.draw.template' => 'std',
669       'application/vnd.sun.xml.impress' => 'sxi',
670       'application/vnd.sun.xml.impress.template' => 'sti',
671       'application/vnd.sun.xml.math' => 'sxm',
672       'application/vnd.sun.xml.writer' => 'sxw',
673       'application/vnd.sun.xml.writer.global' => 'sxg',
674       'application/vnd.sun.xml.writer.template' => 'stw',
675       'application/vnd.sus-calendar' => 'sus',
676       'application/vnd.vidsoft.vidconference' => 'vsc',
677       'application/vnd.visio' => 'vsd',
678       'application/vnd.visionary' => 'vis',
679       'application/vnd.wap.sic' => 'sic',
680       'application/vnd.wap.slc' => 'slc',
681       'application/vnd.wap.wbxml' => 'wbxml',
682       'application/vnd.wap.wmlc' => 'wmlc',
683       'application/vnd.wap.wmlscriptc' => 'wmlsc',
684       'application/vnd.webturbo' => 'wtb',
685       'application/vnd.wordperfect' => 'wpd',
686       'application/vnd.wqd' => 'wqd',
687       'application/vnd.wv.csp+wbxml' => 'wv',
688       'application/vnd.wv.csp+xml' => '8bit',
689       'application/vnd.wv.ssp+xml' => '8bit',
690       'application/vnd.yamaha.hv-dic' => 'hvd',
691       'application/vnd.yamaha.hv-script' => 'hvs',
692       'application/vnd.yamaha.hv-voice' => 'hvp',
693       'application/vnd.yamaha.smaf-audio' => 'saf',
694       'application/vnd.yamaha.smaf-phrase' => 'spf',
695       'application/vocaltec-media-desc' => 'vmd',
696       'application/vocaltec-media-file' => 'vmf',
697       'application/vocaltec-talker' => 'vtk',
698       'application/watcherinfo+xml' => 'wif',
699       'application/wordperfect5.1' => 'wp5',
700       'application/x-123' => 'wk',
701       'application/x-7th_level_event' => '7ls',
702       'application/x-authorware-bin' => 'aab',
703       'application/x-authorware-map' => 'aam',
704       'application/x-authorware-seg' => 'aas',
705       'application/x-bcpio' => 'bcpio',
706       'application/x-bleeper' => 'bleep',
707       'application/x-bzip2' => 'bz2',
708       'application/x-cdlink' => 'vcd',
709       'application/x-chat' => 'chat',
710       'application/x-chess-pgn' => 'pgn',
711       'application/x-compress' => 'z',
712       'application/x-cpio' => 'cpio',
713       'application/x-cprplayer' => 'pqf',
714       'application/x-csh' => 'csh',
715       'application/x-cu-seeme' => 'csm',
716       'application/x-cult3d-object' => 'co',
717       'application/x-debian-package' => 'deb',
718       'application/x-director' => 'dcr',
719       'application/x-dvi' => 'dvi',
720       'application/x-envoy' => 'evy',
721       'application/x-futuresplash' => 'spl',
722       'application/x-gtar' => 'gtar',
723       'application/x-gzip' => 'gz',
724       'application/x-hdf' => 'hdf',
725       'application/x-hep' => 'hep',
726       'application/x-html+ruby' => 'rhtml',
727       'application/x-httpd-miva' => 'mv',
728       'application/x-httpd-php' => 'phtml',
729       'application/x-ica' => 'ica',
730       'application/x-imagemap' => 'imagemap',
731       'application/x-ipix' => 'ipx',
732       'application/x-ipscript' => 'ips',
733       'application/x-java-archive' => 'jar',
734       'application/x-java-jnlp-file' => 'jnlp',
735       'application/x-java-serialized-object' => 'ser',
736       'application/x-java-vm' => 'class',
737       'application/x-javascript' => 'js',
738       'application/x-koan' => 'skp',
739       'application/x-latex' => 'latex',
740       'application/x-mac-compactpro' => 'cpt',
741       'application/x-maker' => 'frm',
742       'application/x-mathcad' => 'mcd',
743       'application/x-midi' => 'mid',
744       'application/x-mif' => 'mif',
745       'application/x-msaccess' => 'mda',
746       'application/x-msdos-program' => 'com',
747       'application/x-msdownload' => 'base64',
748       'application/x-msexcel' => 'xls',
749       'application/x-msword' => 'doc',
750       'application/x-netcdf' => 'nc',
751       'application/x-ns-proxy-autoconfig' => 'pac',
752       'application/x-pagemaker' => 'pm5',
753       'application/x-perl' => 'pl',
754       'application/x-pn-realmedia' => 'rp',
755       'application/x-python' => 'py',
756       'application/x-quicktimeplayer' => 'qtl',
757       'application/x-rar-compressed' => 'rar',
758       'application/x-ruby' => 'rb',
759       'application/x-sh' => 'sh',
760       'application/x-shar' => 'shar',
761       'application/x-shockwave-flash' => 'swf',
762       'application/x-sprite' => 'spr',
763       'application/x-spss' => 'sav',
764       'application/x-spt' => 'spt',
765       'application/x-stuffit' => 'sit',
766       'application/x-sv4cpio' => 'sv4cpio',
767       'application/x-sv4crc' => 'sv4crc',
768       'application/x-tar' => 'tar',
769       'application/x-tcl' => 'tcl',
770       'application/x-tex' => 'tex',
771       'application/x-texinfo' => 'texinfo',
772       'application/x-troff' => 't',
773       'application/x-troff-man' => 'man',
774       'application/x-troff-me' => 'me',
775       'application/x-troff-ms' => 'ms',
776       'application/x-twinvq' => 'vqf',
777       'application/x-twinvq-plugin' => 'vqe',
778       'application/x-ustar' => 'ustar',
779       'application/x-vmsbackup' => 'bck',
780       'application/x-wais-source' => 'src',
781       'application/x-wingz' => 'wz',
782       'application/x-word' => 'base64',
783       'application/x-wordperfect6.1' => 'wp6',
784       'application/x-x509-ca-cert' => 'crt',
785       'application/x-zip' => 'zip',
786       'application/x-zip-compressed' => 'zip',
787       'application/xhtml+xml' => 'xhtml',
788       'application/zip' => 'zip',
789       'audio/3gpp' => '3gpp',
790       'audio/amr' => 'amr',
791       'audio/amr-wb' => 'awb',
792       'audio/basic' => 'au',
793       'audio/evrc' => 'evc',
794       'audio/l16' => 'l16',
795       'audio/midi' => 'mid',
796       'audio/mpeg' => 'mp3',
797       'audio/prs.sid' => 'sid',
798       'audio/qcelp' => 'qcp',
799       'audio/smv' => 'smv',
800       'audio/vnd.audiokoz' => 'koz',
801       'audio/vnd.digital-winds' => 'eol',
802       'audio/vnd.everad.plj' => 'plj',
803       'audio/vnd.lucent.voice' => 'lvp',
804       'audio/vnd.nokia.mobile-xmf' => 'mxmf',
805       'audio/vnd.nortel.vbk' => 'vbk',
806       'audio/vnd.nuera.ecelp4800' => 'ecelp4800',
807       'audio/vnd.nuera.ecelp7470' => 'ecelp7470',
808       'audio/vnd.nuera.ecelp9600' => 'ecelp9600',
809       'audio/vnd.sealedmedia.softseal.mpeg' => 'smp3',
810       'audio/voxware' => 'vox',
811       'audio/x-aiff' => 'aif',
812       'audio/x-mid' => 'mid',
813       'audio/x-midi' => 'mid',
814       'audio/x-mpeg' => 'mp2',
815       'audio/x-mpegurl' => 'mpu',
816       'audio/x-pn-realaudio' => 'rm',
817       'audio/x-pn-realaudio-plugin' => 'rpm',
818       'audio/x-realaudio' => 'ra',
819       'audio/x-wav' => 'wav',
820       'chemical/x-csml' => 'csm',
821       'chemical/x-embl-dl-nucleotide' => 'emb',
822       'chemical/x-gaussian-cube' => 'cube',
823       'chemical/x-gaussian-input' => 'gau',
824       'chemical/x-jcamp-dx' => 'jdx',
825       'chemical/x-mdl-molfile' => 'mol',
826       'chemical/x-mdl-rxnfile' => 'rxn',
827       'chemical/x-mdl-tgf' => 'tgf',
828       'chemical/x-mopac-input' => 'mop',
829       'chemical/x-pdb' => 'pdb',
830       'chemical/x-rasmol' => 'scr',
831       'chemical/x-xyz' => 'xyz',
832       'drawing/dwf' => 'dwf',
833       'drawing/x-dwf' => 'dwf',
834       'i-world/i-vrml' => 'ivr',
835       'image/bmp' => 'bmp',
836       'image/cewavelet' => 'wif',
837       'image/cis-cod' => 'cod',
838       'image/fif' => 'fif',
839       'image/gif' => 'gif',
840       'image/ief' => 'ief',
841       'image/jp2' => 'jp2',
842       'image/jpeg' => 'jpg',
843       'image/jpm' => 'jpm',
844       'image/jpx' => 'jpf',
845       'image/pict' => 'pic',
846       'image/pjpeg' => 'jpg',
847       'image/png' => 'png',
848       'image/targa' => 'tga',
849       'image/tiff' => 'tif',
850       'image/vn-svf' => 'svf',
851       'image/vnd.dgn' => 'dgn',
852       'image/vnd.djvu' => 'djvu',
853       'image/vnd.dwg' => 'dwg',
854       'image/vnd.glocalgraphics.pgb' => 'pgb',
855       'image/vnd.microsoft.icon' => 'ico',
856       'image/vnd.ms-modi' => 'mdi',
857       'image/vnd.sealed.png' => 'spng',
858       'image/vnd.sealedmedia.softseal.gif' => 'sgif',
859       'image/vnd.sealedmedia.softseal.jpg' => 'sjpg',
860       'image/vnd.wap.wbmp' => 'wbmp',
861       'image/x-bmp' => 'bmp',
862       'image/x-cmu-raster' => 'ras',
863       'image/x-freehand' => 'fh4',
864       'image/x-png' => 'png',
865       'image/x-portable-anymap' => 'pnm',
866       'image/x-portable-bitmap' => 'pbm',
867       'image/x-portable-graymap' => 'pgm',
868       'image/x-portable-pixmap' => 'ppm',
869       'image/x-rgb' => 'rgb',
870       'image/x-xbitmap' => 'xbm',
871       'image/x-xpixmap' => 'xpm',
872       'image/x-xwindowdump' => 'xwd',
873       'message/external-body' => '8bit',
874       'message/news' => '8bit',
875       'message/partial' => '8bit',
876       'message/rfc822' => '8bit',
877       'model/iges' => 'igs',
878       'model/mesh' => 'msh',
879       'model/vnd.parasolid.transmit.binary' => 'x_b',
880       'model/vnd.parasolid.transmit.text' => 'x_t',
881       'model/vrml' => 'wrl',
882       'multipart/alternative' => '8bit',
883       'multipart/appledouble' => '8bit',
884       'multipart/digest' => '8bit',
885       'multipart/mixed' => '8bit',
886       'multipart/parallel' => '8bit',
887       'text/comma-separated-values' => 'csv',
888       'text/css' => 'css',
889       'text/html' => 'html',
890       'text/plain' => 'txt',
891       'text/prs.fallenstein.rst' => 'rst',
892       'text/richtext' => 'rtx',
893       'text/rtf' => 'rtf',
894       'text/sgml' => 'sgml',
895       'text/tab-separated-values' => 'tsv',
896       'text/vnd.net2phone.commcenter.command' => 'ccc',
897       'text/vnd.sun.j2me.app-descriptor' => 'jad',
898       'text/vnd.wap.si' => 'si',
899       'text/vnd.wap.sl' => 'sl',
900       'text/vnd.wap.wml' => 'wml',
901       'text/vnd.wap.wmlscript' => 'wmls',
902       'text/x-hdml' => 'hdml',
903       'text/x-setext' => 'etx',
904       'text/x-sgml' => 'sgml',
905       'text/x-speech' => 'talk',
906       'text/x-vcalendar' => 'vcs',
907       'text/x-vcard' => 'vcf',
908       'text/xml' => 'xml',
909       'ulead/vrml' => 'uvr',
910       'video/3gpp' => '3gp',
911       'video/dl' => 'dl',
912       'video/gl' => 'gl',
913       'video/mj2' => 'mj2',
914       'video/mpeg' => 'mpeg',
915       'video/quicktime' => 'mov',
916       'video/vdo' => 'vdo',
917       'video/vivo' => 'viv',
918       'video/vnd.fvt' => 'fvt',
919       'video/vnd.mpegurl' => 'mxu',
920       'video/vnd.nokia.interleaved-multimedia' => 'nim',
921       'video/vnd.objectvideo' => 'mp4',
922       'video/vnd.sealed.mpeg1' => 's11',
923       'video/vnd.sealed.mpeg4' => 'smpg',
924       'video/vnd.sealed.swf' => 'sswf',
925       'video/vnd.sealedmedia.softseal.mov' => 'smov',
926       'video/vnd.vivo' => 'vivo',
927       'video/x-fli' => 'fli',
928       'video/x-ms-asf' => 'asf',
929       'video/x-ms-wmv' => 'wmv',
930       'video/x-msvideo' => 'avi',
931       'video/x-sgi-movie' => 'movie',
932       'x-chemical/x-pdb' => 'pdb',
933       'x-chemical/x-xyz' => 'xyz',
934       'x-conference/x-cooltalk' => 'ice',
935       'x-drawing/dwf' => 'dwf',
936       'x-world/x-d96' => 'd',
937       'x-world/x-svr' => 'svr',
938       'x-world/x-vream' => 'vrw',
939       'x-world/x-vrml' => 'wrl',
940     );
941
942     return !$type ? $default : (isset($extensions[$type]) ? '.'.$extensions[$type] : $default);
943   }
944 }
945
Note: See TracBrowser for help on using the browser.