note 102196 deleted from function.mime-content-type by danbrown

From: Date: Wed, 02 Feb 2011 04:31:05 +0000
Subject: note 102196 deleted from function.mime-content-type by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176586@lists.php.net to get a copy of this message
Note Submitter: supaluk at hotmail dot com ---- <?php function getmime($extension,$default='application/octet-stream'){ if($extension=='') return $default; $tmime=' txt text/plain htm,html,php text/html css text/css js application/javascript json application/json xml application/xml swf application/x-shockwave-flash flv video/x-flv png image/png jpg,jpe,jpeg image/jpeg gif image/gif bmp image/bmp ico image/vnd.microsoft.icon tif,tiff image/tiff svg,svgz image/svg+xml zip application/zip rar application/x-rar-compressed exe,msi application/x-msdownload cab application/vnd.ms-cab-compressed mp3 audio/mpeg qt video/quicktime mov video/quicktime pdf application/pdf psd image/vnd.adobe.photoshop ai application/postscript eps application/postscript ps application/postscript doc,dot application/msword rtf application/rtf xls application/vnd.ms-excel ppt application/vnd.ms-powerpoint odt application/vnd.oasis.opendocument.text ods application/vnd.oasis.opendocument.spreadsheet '; preg_match_all('/'.$extension.'[,+a-z]*+\s(.*)/',$tmime,$ret); return $ret[1][0]?$ret[1][0]:$default; } $test[]=getmime('jpg'); $test[]=getmime('png'); $test[]=getmime('js'); $test[]=getmime('json'); $test[]=getmime('doc'); $test[]=getmime('foo'); $test[]=getmime(''); print_r($test); /* result: Array ( [0] => image/jpeg [1] => image/png [2] => application/javascript [3] => application/json [4] => application/msword [5] => application/octet-stream [6] => application/octet-stream ) */ ?> Sorry I cannot speak english.

« previous php.notes (#176586) next »