note 102196 added to function.mime-content-type
| From: | supaluk at hotmail dot com | Date: | Wed, 02 Feb 2011 03:50:19 +0000 |
| Subject: | note 102196 added to function.mime-content-type | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176582@lists.php.net to get a copy of this message | ||
<?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.
----
Server IP: 203.121.145.220
Probable Submitter: 223.207.63.248
----
Manual Page -- http://www.php.net/manual/en/function.mime-content-type.php
Edit -- https://master.php.net/note/edit/102196
Del: integrated -- https://master.php.net/note/delete/102196/integrated
Del: useless -- https://master.php.net/note/delete/102196/useless
Del: bad code -- https://master.php.net/note/delete/102196/bad+code
Del: spam -- https://master.php.net/note/delete/102196/spam
Del: non-english -- https://master.php.net/note/delete/102196/non-english
Del: in docs -- https://master.php.net/note/delete/102196/in+docs
Del: other reasons-- https://master.php.net/note/delete/102196
Reject -- https://master.php.net/note/reject/102196
Search -- https://master.php.net/manage/user-notes.php