Development

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

You must first sign up to be able to contribute.

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

Revision 18164, 29.5 kB (checked in by fabien, 6 years ago)

[1.1, 1.2, 1.3] fixed error message when an UPLOAD_ERR_INI_SIZE occurs on an uploaded file (closes #6453)

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