summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorAdrian Lang <lang@cosmocode.de>2010-06-22 17:53:16 +0200
committerAdrian Lang <lang@cosmocode.de>2010-08-06 10:52:16 +0200
commitad74fe66da948c8b81b18398a6dbd9583d3741f5 (patch)
tree1faf7356311b18f040aaefd5fadd625e079f7fea /inc
parent7e7f15ca0aadcdadcb930ab025be1c7311365078 (diff)
downloadrpg-ad74fe66da948c8b81b18398a6dbd9583d3741f5.tar.gz
rpg-ad74fe66da948c8b81b18398a6dbd9583d3741f5.tar.bz2
Rewrite mimetype (faster, shorter, no PHP Notice)
Diffstat (limited to 'inc')
-rw-r--r--inc/confutils.php33
1 files changed, 14 insertions, 19 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
index 0c1c0c64a..4306dab8f 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -16,29 +16,24 @@
* @author Andreas Gohr <andi@splitbrain.org>
*/
function mimetype($file, $knownonly=true){
- $ret = array(false,false,false); // return array
$mtypes = getMimeTypes(); // known mimetypes
- $exts = join('|',array_keys($mtypes)); // known extensions (regexp)
- if(!$knownonly){
- $exts = $exts.'|[_\-A-Za-z0-9]+'; // any extension
+ $ext = strrpos($file, '.');
+ if ($ext === false) {
+ return array(false, false, false);
}
- if(preg_match('#\.('.$exts.')$#i',$file,$matches)){
- $ext = strtolower($matches[1]);
- }
-
- if($ext){
- if (isset($mtypes[$ext])){
- if($mtypes[$ext][0] == '!'){
- $ret = array($ext, substr($mtypes[$ext],1), true);
- }else{
- $ret = array($ext, $mtypes[$ext], false);
- }
- }elseif(!$knownonly){
- $ret = array($ext, 'application/octet-stream', true);
+ $ext = strtolower(substr($file, $ext + 1));
+ if (!isset($mtypes[$ext])){
+ if ($knownonly) {
+ return array(false, false, false);
+ } else {
+ return array($ext, 'application/octet-stream', true);
}
}
-
- return $ret;
+ if($mtypes[$ext][0] == '!'){
+ return array($ext, substr($mtypes[$ext],1), true);
+ }else{
+ return array($ext, $mtypes[$ext], false);
+ }
}
/**