PageRenderTime 47ms CodeModel.GetById 14ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

/administrator/components/com_zoo/framework/helpers/filesystem.php

https://gitlab.com/vnsoftdev/amms
PHP | 757 lines | 617 code | 47 blank | 93 comment | 31 complexity | cadbc3eb8ddbec991053cc2fc25cda38 MD5 | raw file
  1<?php
  2/**
  3 * @package   com_zoo
  4 * @author    YOOtheme http://www.yootheme.com
  5 * @copyright Copyright (C) YOOtheme GmbH
  6 * @license   http://www.gnu.org/licenses/gpl.html GNU/GPL
  7 */
  8
  9/**
 10 * Filesystem Helper. Deals with files and directories
 11 *
 12 * @package Framework.Helpers
 13 */
 14class FilesystemHelper extends AppHelper {
 15
 16	/**
 17	 * Get a file size with a suffix (B, KB, MB, etc)
 18	 *
 19	 * @param int $bytes The number of bytes
 20	 *
 21	 * @return string The file size with a suffix
 22	 *
 23	 * @since 1.0.0
 24	 */
 25	public function formatFilesize($bytes) {
 26		$exp    = 0;
 27		$value  = 0;
 28		$symbol = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
 29
 30		if ($bytes > 0) {
 31			$exp   = floor( log($bytes)/log(1024));
 32			$value = ($bytes/pow(1024,floor($exp)));
 33		}
 34
 35		return sprintf('%.2f '.$symbol[$exp], $value);
 36	}
 37
 38	/**
 39	 * Output a file to the browser
 40	 *
 41	 * @param string $file The file to output
 42	 *
 43	 * @since 1.0.0
 44	 */
 45	public function output($file) {
 46		@error_reporting(E_ERROR);
 47
 48		$name = basename($file);
 49		$type = $this->getContentType($name);
 50		$size = @filesize($file);
 51		$mod  = date('r', filemtime($file));
 52
 53		while (@ob_end_clean());
 54
 55		// required for IE, otherwise Content-disposition is ignored
 56		if (ini_get('zlib.output_compression')) {
 57			ini_set('zlib.output_compression', 'Off');
 58		}
 59
 60		// set header
 61        header("Pragma: public");
 62        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 63        header("Expires: 0");
 64        header("Content-Transfer-Encoding: binary");
 65		header('Content-Type: '.$type);
 66		header('Content-Disposition: attachment;'
 67			  .' filename="'.$name.'";'
 68			  .' modification-date="'.$mod.'";'
 69			  .' size='.$size.';');
 70        header("Content-Length: ".$size);
 71
 72		// set_time_limit doesn't work in safe mode
 73        if (!ini_get('safe_mode')) {
 74		    @set_time_limit(0);
 75        }
 76
 77		// output file
 78		$handle = fopen($file, 'rb');
 79		fpassthru($handle);
 80		fclose($handle);
 81	}
 82
 83	/**
 84	 * Get a list of directories from the given directory
 85	 *
 86	 * @param string $path The path of the directory
 87	 * @param string $prefix A prefix to prepend
 88	 * @param string $filter A regex used to filter directories
 89	 * @param boolean $recursive If the search should be recursive (default: true)
 90	 *
 91	 * @return array The list of subdirectories
 92	 *
 93	 * @since 1.0.0
 94	 */
 95	public function readDirectory($path, $prefix = '', $filter = false, $recursive = true) {
 96
 97		$dirs   = array();
 98	    $ignore = array('.', '..', '.DS_Store', '.svn', '.git', '.gitignore', '.gitmodules', 'cgi-bin');
 99
100		if (is_readable($path) && is_dir($path) && $handle = @opendir($path)) {
101			while (false !== ($file = readdir($handle))) {
102
103				// continue if ignore match
104				if (in_array($file, $ignore)) {
105					continue;
106				}
107
108	            if (is_dir($path.'/'.$file)) {
109
110					// continue if not recursive
111					if (!$recursive) {
112						continue;
113					}
114
115					// continue if no regex filter match
116					if ($filter && !preg_match($filter, $file)) {
117						continue;
118					}
119
120					// read subdirectory
121					$dirs[] = $prefix.$file;
122	            	$dirs   = array_merge($dirs, $this->readDirectory($path.'/'.$file, $prefix.$file.'/', $filter, $recursive));
123
124				}
125		    }
126		    closedir($handle);
127		}
128
129		return $dirs;
130	}
131
132	/**
133	 * Get a list of files in the given directory
134	 *
135	 * @param string $path The path to search in
136	 * @param string $prefix A prefix to prepend
137	 * @param string $filter A regex to filter the files
138	 * @param boolean $recursive If the search should be recursive (default: true)
139	 *
140	 * @return array The list of files
141	 *
142	 * @since 1.0.0
143	 */
144	public function readDirectoryFiles($path, $prefix = '', $filter = false, $recursive = true) {
145
146		$files  = array();
147	    $ignore = array('.', '..', '.DS_Store', '.svn', '.git', '.gitignore', '.gitmodules', 'cgi-bin');
148
149		if (is_readable($path) && is_dir($path) && $handle = @opendir($path)) {
150			while (false !== ($file = readdir($handle))) {
151
152				// continue if ignore match
153				if (in_array($file, $ignore)) {
154					continue;
155				}
156
157	            if (is_dir($path.'/'.$file)) {
158
159					// continue if not recursive
160					if (!$recursive) {
161						continue;
162					}
163
164					// read subdirectory
165	            	$files = array_merge($files, $this->readDirectoryFiles($path.'/'.$file, $prefix.$file.'/', $filter, $recursive));
166
167				} else {
168
169					// continue if no regex filter match
170					if ($filter && !preg_match($filter, $file)) {
171						continue;
172					}
173
174					$files[] = $prefix.$file;
175	            }
176		    }
177		    closedir($handle);
178		}
179
180		return $files;
181	}
182
183	/**
184	 * Get the file extension
185	 *
186	 * @param string $filename The file name
187	 *
188	 * @return string The file extension
189	 *
190	 * @since 1.0.0
191	 */
192	public function getExtension($filename) {
193		$mimes = $this->getMimeMapping();
194		$file  = pathinfo($filename);
195		$ext   = isset($file['extension']) ? $file['extension'] : null;
196
197		if ($ext) {
198
199			// check extensions content type (with dot, like tar.gz)
200			if (($pos = strrpos($file['filename'], '.')) !== false) {
201				$ext2 = strtolower(substr($file['filename'], $pos + 1).'.'.$ext);
202				if (array_key_exists($ext2, $mimes)) {
203					return $ext2;
204				}
205			}
206
207			// check extensions content type
208			$ext = strtolower($ext);
209			if (array_key_exists(strtolower($ext), $mimes)) {
210				return $ext;
211			}
212		}
213
214		return null;
215	}
216
217	/**
218	 * Get the content type of a file
219	 *
220	 * @param string $filename The file name
221	 *
222	 * @return string The content type
223	 *
224	 * @since 1.0.0
225	 */
226	public function getContentType($filename) {
227		$mimes = $this->getMimeMapping();
228		$file  = pathinfo($filename);
229		$ext   = $file['extension'];
230
231		if ($ext) {
232
233			// check extensions content type (with dot, like tar.gz)
234			if (($pos = strrpos($file['filename'], '.')) !== false) {
235				$ext2 = strtolower(substr($file['filename'], $pos + 1).'.'.$ext);
236				if (array_key_exists($ext2, $mimes)) {
237					return array_shift($mimes[$ext2]);
238				}
239			}
240
241			// check extensions content type
242			$ext = strtolower($ext);
243			if (array_key_exists(strtolower($ext), $mimes)) {
244				return array_shift($mimes[$ext]);
245			}
246		}
247
248		return 'application/octet-stream';
249	}
250
251	/**
252	 * Get the mapping from extension to mime type
253	 *
254	 * @return array The associative array of extension => mime type mapping
255	 *
256	 * @since 1.0.0
257	 */
258	public static function getMimeMapping() {
259
260		$mimes = array();
261		$mimes['3ds'][] = 'image/x-3ds';
262		$mimes['BLEND'][] = 'application/x-blender';
263		$mimes['C'][] = 'text/x-c++src';
264		$mimes['CSSL'][] = 'text/css';
265		$mimes['NSV'][] = 'video/x-nsv';
266		$mimes['XM'][] = 'audio/x-mod';
267		$mimes['Z'][] = 'application/x-compress';
268		$mimes['a'][] = 'application/x-archive';
269		$mimes['abw'][] = 'application/x-abiword';
270		$mimes['abw.gz'][] = 'application/x-abiword';
271		$mimes['ac3'][] = 'audio/ac3';
272		$mimes['adb'][] = 'text/x-adasrc';
273		$mimes['ads'][] = 'text/x-adasrc';
274		$mimes['afm'][] = 'application/x-font-afm';
275		$mimes['ag'][] = 'image/x-applix-graphics';
276		$mimes['ai'][] = 'application/illustrator';
277		$mimes['aif'][] = 'audio/x-aiff';
278		$mimes['aifc'][] = 'audio/x-aiff';
279		$mimes['aiff'][] = 'audio/x-aiff';
280		$mimes['al'][] = 'application/x-perl';
281		$mimes['arj'][] = 'application/x-arj';
282		$mimes['as'][] = 'application/x-applix-spreadsheet';
283		$mimes['asc'][] = 'text/plain';
284		$mimes['asf'][] = 'video/x-ms-asf';
285		$mimes['asp'][] = 'application/x-asp';
286		$mimes['asx'][] = 'video/x-ms-asf';
287		$mimes['au'][] = 'audio/basic';
288		$mimes['avi'][] = 'video/x-msvideo';
289		$mimes['avi'][] = 'video/avi';  // IE
290		$mimes['aw'][] = 'application/x-applix-word';
291		$mimes['bak'][] = 'application/x-trash';
292		$mimes['bcpio'][] = 'application/x-bcpio';
293		$mimes['bdf'][] = 'application/x-font-bdf';
294		$mimes['bib'][] = 'text/x-bibtex';
295		$mimes['bin'][] = 'application/octet-stream';
296		$mimes['blend'][] = 'application/x-blender';
297		$mimes['blender'][] = 'application/x-blender';
298		$mimes['bmp'][] = 'image/bmp';
299		$mimes['bz'][] = 'application/x-bzip';
300		$mimes['bz2'][] = 'application/x-bzip';
301		$mimes['c'][] = 'text/x-csrc';
302		$mimes['c++'][] = 'text/x-c++src';
303		$mimes['cc'][] = 'text/x-c++src';
304		$mimes['cdf'][] = 'application/x-netcdf';
305		$mimes['cdr'][] = 'application/vnd.corel-draw';
306		$mimes['cer'][] = 'application/x-x509-ca-cert';
307		$mimes['cert'][] = 'application/x-x509-ca-cert';
308		$mimes['cgi'][] = 'application/x-cgi';
309		$mimes['cgm'][] = 'image/cgm';
310		$mimes['chrt'][] = 'application/x-kchart';
311		$mimes['class'][] = 'application/x-java';
312		$mimes['cls'][] = 'text/x-tex';
313		$mimes['cpio'][] = 'application/x-cpio';
314		$mimes['cpio.gz'][] = 'application/x-cpio-compressed';
315		$mimes['cpp'][] = 'text/x-c++src';
316		$mimes['cpt'][] = 'application/mac-compactpro';
317		$mimes['crt'][] = 'application/x-x509-ca-cert';
318		$mimes['cs'][] = 'text/x-csharp';
319		$mimes['csh'][] = 'application/x-shellscript';
320		$mimes['css'][] = 'text/css';
321		$mimes['csv'][] = 'text/x-comma-separated-values';
322		$mimes['cur'][] = 'image/x-win-bitmap';
323		$mimes['cxx'][] = 'text/x-c++src';
324		$mimes['dat'][] = 'video/mpeg';
325		$mimes['dbf'][] = 'application/x-dbase';
326		$mimes['dc'][] = 'application/x-dc-rom';
327		$mimes['dcl'][] = 'text/x-dcl';
328		$mimes['dcm'][] = 'image/x-dcm';
329		$mimes['dcr'][] = 'application/x-director';
330		$mimes['dd2'][] = 'application/vnd.oma.dd2+xml';
331		$mimes['deb'][] = 'application/x-deb';
332		$mimes['der'][] = 'application/x-x509-ca-cert';
333		$mimes['desktop'][] = 'application/x-desktop';
334		$mimes['dia'][] = 'application/x-dia-diagram';
335		$mimes['diff'][] = 'text/x-patch';
336		$mimes['dir'][] = 'application/x-director';
337		$mimes['djv'][] = 'image/vnd.djvu';
338		$mimes['djvu'][] = 'image/vnd.djvu';
339		$mimes['dll'][] = 'application/octet-stream';
340		$mimes['dms'][] = 'application/octet-stream';
341		$mimes['doc'][] = 'application/msword';
342		$mimes['dsl'][] = 'text/x-dsl';
343		$mimes['dtd'][] = 'text/x-dtd';
344		$mimes['dvi'][] = 'application/x-dvi';
345		$mimes['dwg'][] = 'image/vnd.dwg';
346		$mimes['dxf'][] = 'image/vnd.dxf';
347		$mimes['dxr'][] = 'application/x-director';
348		$mimes['egon'][] = 'application/x-egon';
349		$mimes['el'][] = 'text/x-emacs-lisp';
350		$mimes['eps'][] = 'image/x-eps';
351		$mimes['epsf'][] = 'image/x-eps';
352		$mimes['epsi'][] = 'image/x-eps';
353		$mimes['etheme'][] = 'application/x-e-theme';
354		$mimes['etx'][] = 'text/x-setext';
355		$mimes['exe'][] = 'application/x-executable';
356		$mimes['exe'][] = 'application/x-msdownload';  // IE
357		$mimes['ez'][] = 'application/andrew-inset';
358		$mimes['f'][] = 'text/x-fortran';
359		$mimes['fig'][] = 'image/x-xfig';
360		$mimes['fits'][] = 'image/x-fits';
361		$mimes['flac'][] = 'audio/x-flac';
362		$mimes['flc'][] = 'video/x-flic';
363		$mimes['fli'][] = 'video/x-flic';
364		$mimes['flv'][] = 'video/x-flv';
365		$mimes['flw'][] = 'application/x-kivio';
366		$mimes['fo'][] = 'text/x-xslfo';
367		$mimes['g3'][] = 'image/fax-g3';
368		$mimes['gb'][] = 'application/x-gameboy-rom';
369		$mimes['gcrd'][] = 'text/x-vcard';
370		$mimes['gen'][] = 'application/x-genesis-rom';
371		$mimes['gg'][] = 'application/x-sms-rom';
372		$mimes['gif'][] = 'image/gif';
373		$mimes['glade'][] = 'application/x-glade';
374		$mimes['gmo'][] = 'application/x-gettext-translation';
375		$mimes['gnc'][] = 'application/x-gnucash';
376		$mimes['gnucash'][] = 'application/x-gnucash';
377		$mimes['gnumeric'][] = 'application/x-gnumeric';
378		$mimes['gra'][] = 'application/x-graphite';
379		$mimes['gsf'][] = 'application/x-font-type1';
380		$mimes['gtar'][] = 'application/x-gtar';
381		$mimes['gz'][] = 'application/gzip';
382		$mimes['gz'][] = 'application/x-gzip';
383		$mimes['gz'][] = 'application/x-gzip-compressed'; // IE
384		$mimes['h'][] = 'text/x-chdr';
385		$mimes['h++'][] = 'text/x-chdr';
386		$mimes['hdf'][] = 'application/x-hdf';
387		$mimes['hh'][] = 'text/x-c++hdr';
388		$mimes['hp'][] = 'text/x-chdr';
389		$mimes['hpgl'][] = 'application/vnd.hp-hpgl';
390		$mimes['hqx'][] = 'application/mac-binhex40';
391		$mimes['hs'][] = 'text/x-haskell';
392		$mimes['htm'][] = 'text/html';
393		$mimes['html'][] = 'text/html';
394		$mimes['icb'][] = 'image/x-icb';
395		$mimes['ice'][] = 'x-conference/x-cooltalk';
396		$mimes['ico'][] = 'image/x-ico';
397		$mimes['ics'][] = 'text/calendar';
398		$mimes['idl'][] = 'text/x-idl';
399		$mimes['ief'][] = 'image/ief';
400		$mimes['ifb'][] = 'text/calendar';
401		$mimes['iff'][] = 'image/x-iff';
402		$mimes['iges'][] = 'model/iges';
403		$mimes['igs'][] = 'model/iges';
404		$mimes['igs'][] = 'application/iges';
405		$mimes['ilbm'][] = 'image/x-ilbm';
406		$mimes['iso'][] = 'application/x-cd-image';
407		$mimes['it'][] = 'audio/x-it';
408		$mimes['jar'][] = 'application/x-jar';
409		$mimes['java'][] = 'text/x-java';
410		$mimes['jng'][] = 'image/x-jng';
411		$mimes['jp2'][] = 'image/jpeg2000';
412		$mimes['jpg'][] = 'image/jpeg';
413		$mimes['jpg'][] = 'image/pjpeg';  // IE
414		$mimes['jpe'][] = 'image/jpeg';
415		$mimes['jpeg'][] = 'image/jpeg';
416		$mimes['jpeg'][] = 'image/pjpeg';  // IE
417		$mimes['jpr'][] = 'application/x-jbuilder-project';
418		$mimes['jpx'][] = 'application/x-jbuilder-project';
419		$mimes['js'][] = 'application/x-javascript';
420		$mimes['kar'][] = 'audio/midi';
421		$mimes['karbon'][] = 'application/x-karbon';
422		$mimes['kdelnk'][] = 'application/x-desktop';
423		$mimes['kfo'][] = 'application/x-kformula';
424		$mimes['kil'][] = 'application/x-killustrator';
425		$mimes['kon'][] = 'application/x-kontour';
426		$mimes['kpm'][] = 'application/x-kpovmodeler';
427		$mimes['kpr'][] = 'application/x-kpresenter';
428		$mimes['kpt'][] = 'application/x-kpresenter';
429		$mimes['kra'][] = 'application/x-krita';
430		$mimes['ksp'][] = 'application/x-kspread';
431		$mimes['kud'][] = 'application/x-kugar';
432		$mimes['kwd'][] = 'application/x-kword';
433		$mimes['kwt'][] = 'application/x-kword';
434		$mimes['la'][] = 'application/x-shared-library-la';
435		$mimes['latex'][] = 'application/x-latex';
436		$mimes['lha'][] = 'application/x-lha';
437		$mimes['lhs'][] = 'text/x-literate-haskell';
438		$mimes['lhz'][] = 'application/x-lhz';
439		$mimes['log'][] = 'text/x-log';
440		$mimes['ltx'][] = 'text/x-tex';
441		$mimes['lwo'][] = 'image/x-lwo';
442		$mimes['lwob'][] = 'image/x-lwo';
443		$mimes['lws'][] = 'image/x-lws';
444		$mimes['lyx'][] = 'application/x-lyx';
445		$mimes['lzh'][] = 'application/x-lha';
446		$mimes['lzo'][] = 'application/x-lzop';
447		$mimes['m'][] = 'text/x-objcsrc';
448		$mimes['m15'][] = 'audio/x-mod';
449		$mimes['m3u'][] = 'audio/x-mpegurl';
450        $mimes['m4v'][] = 'video/x-m4v';
451		$mimes['man'][] = 'application/x-troff-man';
452		$mimes['md'][] = 'application/x-genesis-rom';
453		$mimes['me'][] = 'text/x-troff-me';
454		$mimes['mesh'][] = 'model/mesh';
455		$mimes['mgp'][] = 'application/x-magicpoint';
456		$mimes['mid'][] = 'audio/midi';
457		$mimes['mid'][] = 'audio/mid'; // IE
458		$mimes['midi'][] = 'audio/midi';
459		$mimes['mif'][] = 'application/x-mif';
460		$mimes['mkv'][] = 'application/x-matroska';
461		$mimes['mm'][] = 'text/x-troff-mm';
462		$mimes['mml'][] = 'text/mathml';
463		$mimes['mng'][] = 'video/x-mng';
464		$mimes['moc'][] = 'text/x-moc';
465		$mimes['mod'][] = 'audio/x-mod';
466		$mimes['moov'][] = 'video/quicktime';
467		$mimes['mov'][] = 'video/quicktime';
468		$mimes['movie'][] = 'video/x-sgi-movie';
469		$mimes['mp2'][] = 'video/mpeg';
470		$mimes['mp3'][] = 'audio/mpeg';
471		$mimes['mp4'][] = 'video/mp4';
472		$mimes['mpe'][] = 'video/mpeg';
473		$mimes['mpeg'][] = 'video/mpeg';
474		$mimes['mpg'][] = 'video/mpeg';
475		$mimes['mpga'][] = 'audio/mpeg';
476		$mimes['ms'][] = 'text/x-troff-ms';
477		$mimes['msh'][] = 'model/mesh';
478		$mimes['msod'][] = 'image/x-msod';
479		$mimes['msx'][] = 'application/x-msx-rom';
480		$mimes['mtm'][] = 'audio/x-mod';
481		$mimes['mxu'][] = 'video/vnd.mpegurl';
482		$mimes['n64'][] = 'application/x-n64-rom';
483		$mimes['nc'][] = 'application/x-netcdf';
484		$mimes['nes'][] = 'application/x-nes-rom';
485		$mimes['nsv'][] = 'video/x-nsv';
486		$mimes['o'][] = 'application/x-object';
487		$mimes['obj'][] = 'application/x-tgif';
488		$mimes['oda'][] = 'application/oda';
489		$mimes['odb'][] = 'application/vnd.oasis.opendocument.database';
490		$mimes['odc'][] = 'application/vnd.oasis.opendocument.chart';
491		$mimes['odf'][] = 'application/vnd.oasis.opendocument.formula';
492		$mimes['odg'][] = 'application/vnd.oasis.opendocument.graphics';
493		$mimes['odi'][] = 'application/vnd.oasis.opendocument.image';
494		$mimes['odm'][] = 'application/vnd.oasis.opendocument.text-master';
495		$mimes['odp'][] = 'application/vnd.oasis.opendocument.presentation';
496		$mimes['ods'][] = 'application/vnd.oasis.opendocument.spreadsheet';
497		$mimes['odt'][] = 'application/vnd.oasis.opendocument.text';
498		$mimes['ogg'][] = 'application/ogg';
499		$mimes['ogx'][] = 'application/ogg';
500		$mimes['oga'][] = 'audio/ogg';
501		$mimes['ogv'][] = 'video/ogg';
502		$mimes['old'][] = 'application/x-trash';
503		$mimes['oleo'][] = 'application/x-oleo';
504		$mimes['otg'][] = 'application/vnd.oasis.opendocument.graphics-template';
505		$mimes['oth'][] = 'application/vnd.oasis.opendocument.text-web';
506		$mimes['otp'][] = 'application/vnd.oasis.opendocument.presentation-template';
507		$mimes['ots'][] = 'application/vnd.oasis.opendocument.spreadsheet-template';
508		$mimes['ott'][] = 'application/vnd.oasis.opendocument.text-template';
509		$mimes['p'][] = 'text/x-pascal';
510		$mimes['p12'][] = 'application/x-pkcs12';
511		$mimes['p7s'][] = 'application/pkcs7-signature';
512		$mimes['pas'][] = 'text/x-pascal';
513		$mimes['patch'][] = 'text/x-patch';
514		$mimes['pbm'][] = 'image/x-portable-bitmap';
515		$mimes['pcd'][] = 'image/x-photo-cd';
516		$mimes['pcf'][] = 'application/x-font-pcf';
517		$mimes['pcf.Z'][] = 'application/x-font-type1';
518		$mimes['pcl'][] = 'application/vnd.hp-pcl';
519		$mimes['pdb'][] = 'application/vnd.palm';
520		$mimes['pdf'][] = 'application/pdf';
521		$mimes['pdf'][] = 'application/x-pdf';
522		$mimes['pem'][] = 'application/x-x509-ca-cert';
523		$mimes['perl'][] = 'application/x-perl';
524		$mimes['pfa'][] = 'application/x-font-type1';
525		$mimes['pfb'][] = 'application/x-font-type1';
526		$mimes['pfx'][] = 'application/x-pkcs12';
527		$mimes['pgm'][] = 'image/x-portable-graymap';
528		$mimes['pgn'][] = 'application/x-chess-pgn';
529		$mimes['pgp'][] = 'application/pgp';
530		$mimes['php'][] = 'application/x-php';
531		$mimes['php3'][] = 'application/x-php';
532		$mimes['php4'][] = 'application/x-php';
533		$mimes['pict'][] = 'image/x-pict';
534		$mimes['pict1'][] = 'image/x-pict';
535		$mimes['pict2'][] = 'image/x-pict';
536		$mimes['pl'][] = 'application/x-perl';
537		$mimes['pls'][] = 'audio/x-scpls';
538		$mimes['pm'][] = 'application/x-perl';
539		$mimes['png'][] = 'image/png';
540		$mimes['png'][] = 'image/x-png';  // IE
541		$mimes['pnm'][] = 'image/x-portable-anymap';
542		$mimes['po'][] = 'text/x-gettext-translation';
543		$mimes['pot'][] = 'application/vnd.ms-powerpoint';
544		$mimes['ppm'][] = 'image/x-portable-pixmap';
545		$mimes['pps'][] = 'application/vnd.ms-powerpoint';
546		$mimes['ppt'][] = 'application/vnd.ms-powerpoint';
547		$mimes['ppz'][] = 'application/vnd.ms-powerpoint';
548		$mimes['ps'][] = 'application/postscript';
549		$mimes['ps.gz'][] = 'application/x-gzpostscript';
550		$mimes['psd'][] = 'image/x-psd';
551		$mimes['psf'][] = 'application/x-font-linux-psf';
552		$mimes['psid'][] = 'audio/prs.sid';
553		$mimes['pw'][] = 'application/x-pw';
554		$mimes['py'][] = 'application/x-python';
555		$mimes['pyc'][] = 'application/x-python-bytecode';
556		$mimes['pyo'][] = 'application/x-python-bytecode';
557		$mimes['qif'][] = 'application/x-qw';
558		$mimes['qt'][] = 'video/quicktime';
559		$mimes['qtvr'][] = 'video/quicktime';
560		$mimes['ra'][] = 'audio/x-pn-realaudio';
561		$mimes['ram'][] = 'audio/x-pn-realaudio';
562		$mimes['rar'][] = 'application/x-rar';
563		$mimes['ras'][] = 'image/x-cmu-raster';
564		$mimes['rdf'][] = 'text/rdf';
565		$mimes['rej'][] = 'application/x-reject';
566		$mimes['rgb'][] = 'image/x-rgb';
567		$mimes['rle'][] = 'image/rle';
568		$mimes['rm'][] = 'audio/x-pn-realaudio';
569		$mimes['roff'][] = 'application/x-troff';
570		$mimes['rpm'][] = 'application/x-rpm';
571		$mimes['rss'][] = 'text/rss';
572		$mimes['rtf'][] = 'application/rtf';
573		$mimes['rtx'][] = 'text/richtext';
574		$mimes['s3m'][] = 'audio/x-s3m';
575		$mimes['sam'][] = 'application/x-amipro';
576		$mimes['scm'][] = 'text/x-scheme';
577		$mimes['sda'][] = 'application/vnd.stardivision.draw';
578		$mimes['sdc'][] = 'application/vnd.stardivision.calc';
579		$mimes['sdd'][] = 'application/vnd.stardivision.impress';
580		$mimes['sdp'][] = 'application/vnd.stardivision.impress';
581		$mimes['sds'][] = 'application/vnd.stardivision.chart';
582		$mimes['sdw'][] = 'application/vnd.stardivision.writer';
583		$mimes['sgi'][] = 'image/x-sgi';
584		$mimes['sgl'][] = 'application/vnd.stardivision.writer';
585		$mimes['sgm'][] = 'text/sgml';
586		$mimes['sgml'][] = 'text/sgml';
587		$mimes['sh'][] = 'application/x-shellscript';
588		$mimes['shar'][] = 'application/x-shar';
589		$mimes['shtml'][] = 'text/html';
590		$mimes['siag'][] = 'application/x-siag';
591		$mimes['sid'][] = 'audio/prs.sid';
592		$mimes['sik'][] = 'application/x-trash';
593		$mimes['silo'][] = 'model/mesh';
594		$mimes['sit'][] = 'application/x-stuffit';
595		$mimes['skd'][] = 'application/x-koan';
596		$mimes['skm'][] = 'application/x-koan';
597		$mimes['skp'][] = 'application/x-koan';
598		$mimes['skt'][] = 'application/x-koan';
599		$mimes['slk'][] = 'text/spreadsheet';
600		$mimes['smd'][] = 'application/vnd.stardivision.mail';
601		$mimes['smf'][] = 'application/vnd.stardivision.math';
602		$mimes['smi'][] = 'application/smil';
603		$mimes['smil'][] = 'application/smil';
604		$mimes['sml'][] = 'application/smil';
605		$mimes['sms'][] = 'application/x-sms-rom';
606		$mimes['snd'][] = 'audio/basic';
607		$mimes['so'][] = 'application/x-sharedlib';
608		$mimes['spd'][] = 'application/x-font-speedo';
609		$mimes['spl'][] = 'application/x-futuresplash';
610		$mimes['sql'][] = 'text/x-sql';
611		$mimes['src'][] = 'application/x-wais-source';
612		$mimes['stc'][] = 'application/vnd.sun.xml.calc.template';
613		$mimes['std'][] = 'application/vnd.sun.xml.draw.template';
614		$mimes['sti'][] = 'application/vnd.sun.xml.impress.template';
615		$mimes['stm'][] = 'audio/x-stm';
616		$mimes['stw'][] = 'application/vnd.sun.xml.writer.template';
617		$mimes['sty'][] = 'text/x-tex';
618		$mimes['sun'][] = 'image/x-sun-raster';
619		$mimes['sv4cpio'][] = 'application/x-sv4cpio';
620		$mimes['sv4crc'][] = 'application/x-sv4crc';
621		$mimes['svg'][] = 'image/svg+xml';
622		$mimes['swf'][] = 'application/x-shockwave-flash';
623		$mimes['sxc'][] = 'application/vnd.sun.xml.calc';
624		$mimes['sxd'][] = 'application/vnd.sun.xml.draw';
625		$mimes['sxg'][] = 'application/vnd.sun.xml.writer.global';
626		$mimes['sxi'][] = 'application/vnd.sun.xml.impress';
627		$mimes['sxm'][] = 'application/vnd.sun.xml.math';
628		$mimes['sxw'][] = 'application/vnd.sun.xml.writer';
629		$mimes['sylk'][] = 'text/spreadsheet';
630		$mimes['t'][] = 'application/x-troff';
631		$mimes['tar'][] = 'application/x-tar';
632		$mimes['tar.Z'][] = 'application/x-tarz';
633		$mimes['tar.bz'][] = 'application/x-bzip-compressed-tar';
634		$mimes['tar.bz2'][] = 'application/x-bzip-compressed-tar';
635		$mimes['tar.gz'][] = 'application/x-compressed-tar';
636		$mimes['tar.gz'][] = 'application/x-compressed'; // IE
637		$mimes['tar.lzo'][] = 'application/x-tzo';
638		$mimes['tcl'][] = 'text/x-tcl';
639		$mimes['tex'][] = 'text/x-tex';
640		$mimes['texi'][] = 'text/x-texinfo';
641		$mimes['texinfo'][] = 'text/x-texinfo';
642		$mimes['tga'][] = 'image/x-tga';
643		$mimes['tgz'][] = 'application/x-compressed-tar';
644		$mimes['theme'][] = 'application/x-theme';
645		$mimes['tif'][] = 'image/tiff';
646		$mimes['tiff'][] = 'image/tiff';
647		$mimes['tk'][] = 'text/x-tcl';
648		$mimes['torrent'][] = 'application/x-bittorrent';
649		$mimes['tr'][] = 'application/x-troff';
650		$mimes['ts'][] = 'application/x-linguist';
651		$mimes['tsv'][] = 'text/tab-separated-values';
652		$mimes['ttf'][] = 'application/x-font-ttf';
653		$mimes['txt'][] = 'text/plain';
654		$mimes['tzo'][] = 'application/x-tzo';
655		$mimes['ui'][] = 'application/x-designer';
656		$mimes['uil'][] = 'text/x-uil';
657		$mimes['ult'][] = 'audio/x-mod';
658		$mimes['uni'][] = 'audio/x-mod';
659		$mimes['unity3d'][] = 'application/octet-stream';
660		$mimes['uri'][] = 'text/x-uri';
661		$mimes['url'][] = 'text/x-uri';
662		$mimes['ustar'][] = 'application/x-ustar';
663		$mimes['vcd'][] = 'application/x-cdlink';
664		$mimes['vcf'][] = 'text/x-vcalendar';
665		$mimes['vcs'][] = 'text/x-vcalendar';
666		$mimes['vct'][] = 'text/x-vcard';
667		$mimes['vfb'][] = 'text/calendar';
668		$mimes['vob'][] = 'video/mpeg';
669		$mimes['voc'][] = 'audio/x-voc';
670		$mimes['vor'][] = 'application/vnd.stardivision.writer';
671		$mimes['vrml'][] = 'model/vrml';
672		$mimes['vsd'][] = 'application/vnd.visio';
673		$mimes['wav'][] = 'audio/x-wav';
674		$mimes['wav'][] = 'audio/wav'; // IE
675		$mimes['wax'][] = 'audio/x-ms-wax';
676		$mimes['wb1'][] = 'application/x-quattropro';
677		$mimes['wb2'][] = 'application/x-quattropro';
678		$mimes['wb3'][] = 'application/x-quattropro';
679		$mimes['wbmp'][] = 'image/vnd.wap.wbmp';
680		$mimes['wbxml'][] = 'application/vnd.wap.wbxml';
681		$mimes['wk1'][] = 'application/vnd.lotus-1-2-3';
682		$mimes['wk3'][] = 'application/vnd.lotus-1-2-3';
683		$mimes['wk4'][] = 'application/vnd.lotus-1-2-3';
684		$mimes['wks'][] = 'application/vnd.lotus-1-2-3';
685		$mimes['wm'][] = 'video/x-ms-wm';
686		$mimes['wma'][] = 'audio/x-ms-wma';
687		$mimes['wmd'][] = 'application/x-ms-wmd';
688		$mimes['wmf'][] = 'image/x-wmf';
689		$mimes['wml'][] = 'text/vnd.wap.wml';
690		$mimes['wmlc'][] = 'application/vnd.wap.wmlc';
691		$mimes['wmls'][] = 'text/vnd.wap.wmlscript';
692		$mimes['wmlsc'][] = 'application/vnd.wap.wmlscriptc';
693		$mimes['wmv'][] = 'video/x-ms-wmv';
694		$mimes['wmx'][] = 'video/x-ms-wmx';
695		$mimes['wmz'][] = 'application/x-ms-wmz';
696		$mimes['wpd'][] = 'application/wordperfect';
697		$mimes['wpg'][] = 'application/x-wpg';
698		$mimes['wri'][] = 'application/x-mswrite';
699		$mimes['wrl'][] = 'model/vrml';
700		$mimes['wvx'][] = 'video/x-ms-wvx';
701		$mimes['xac'][] = 'application/x-gnucash';
702		$mimes['xbel'][] = 'application/x-xbel';
703		$mimes['xbm'][] = 'image/x-xbitmap';
704		$mimes['xcf'][] = 'image/x-xcf';
705		$mimes['xcf.bz2'][] = 'image/x-compressed-xcf';
706		$mimes['xcf.gz'][] = 'image/x-compressed-xcf';
707		$mimes['xht'][] = 'application/xhtml+xml';
708		$mimes['xhtml'][] = 'application/xhtml+xml';
709		$mimes['xi'][] = 'audio/x-xi';
710		$mimes['xls'][] = 'application/vnd.ms-excel';
711		$mimes['xla'][] = 'application/vnd.ms-excel';
712		$mimes['xlc'][] = 'application/vnd.ms-excel';
713		$mimes['xld'][] = 'application/vnd.ms-excel';
714		$mimes['xll'][] = 'application/vnd.ms-excel';
715		$mimes['xlm'][] = 'application/vnd.ms-excel';
716		$mimes['xlt'][] = 'application/vnd.ms-excel';
717		$mimes['xlw'][] = 'application/vnd.ms-excel';
718		$mimes['xm'][] = 'audio/x-xm';
719		$mimes['xml'][] = 'text/xml';
720		$mimes['xml'][] = 'application/xml'; // IE
721		$mimes['xpm'][] = 'image/x-xpixmap';
722		$mimes['xsl'][] = 'text/x-xslt';
723		$mimes['xslfo'][] = 'text/x-xslfo';
724		$mimes['xslt'][] = 'text/x-xslt';
725		$mimes['xwd'][] = 'image/x-xwindowdump';
726		$mimes['xyz'][] = 'chemical/x-xyz';
727		$mimes['zabw'][] = 'application/x-abiword';
728		$mimes['zip'][] = 'application/zip';
729		$mimes['zip'][] = 'application/x-zip';
730		$mimes['zip'][] = 'application/x-zip-compressed'; // IE
731		$mimes['zoo'][] = 'application/x-zoo';
732		$mimes['123'][] = 'application/vnd.lotus-1-2-3';
733		$mimes['669'][] = 'audio/x-mod';
734
735		// office 2007
736		$mimes['docm'][] = 'application/vnd.ms-word.document.macroEnabled.12';
737		$mimes['docx'][] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
738		$mimes['dotm'][] = 'application/vnd.ms-word.template.macroEnabled.12';
739		$mimes['dotx'][] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template';
740		$mimes['potm'][] = 'application/vnd.ms-powerpoint.template.macroEnabled.12';
741		$mimes['potx'][] = 'application/vnd.openxmlformats-officedocument.presentationml.template';
742		$mimes['ppam'][] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12';
743		$mimes['ppsm'][] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12';
744		$mimes['ppsx'][] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow';
745		$mimes['pptm'][] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12';
746		$mimes['pptx'][] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
747		$mimes['xlam'][] = 'application/vnd.ms-excel.addin.macroEnabled.12';
748		$mimes['xlsb'][] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12';
749		$mimes['xlsm'][] = 'application/vnd.ms-excel.sheet.macroEnabled.12';
750		$mimes['xlsx'][] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
751		$mimes['xltm'][] = 'application/vnd.ms-excel.template.macroEnabled.12';
752		$mimes['xltx'][] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template';
753
754		return $mimes;
755	}
756
757}