summaryrefslogtreecommitdiff
path: root/inc/confutils.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/confutils.php')
-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);
+ }
}
/**