summaryrefslogtreecommitdiff
path: root/inc/confutils.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/confutils.php')
-rw-r--r--inc/confutils.php22
1 files changed, 16 insertions, 6 deletions
diff --git a/inc/confutils.php b/inc/confutils.php
index aab0be4be..5ad8385c4 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -10,21 +10,31 @@
/**
* Returns the (known) extension and mimetype of a given filename
*
+ * If $knownonly is true (the default), then only known extensions
+ * are returned.
+ *
* @author Andreas Gohr <andi@splitbrain.org>
*/
-function mimetype($file){
+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
+ }
if(preg_match('#\.('.$exts.')$#i',$file,$matches)){
$ext = strtolower($matches[1]);
}
- if($ext && $mtypes[$ext]){
- if($mtypes[$ext][0] == '!'){
- $ret = array($ext, substr($mtypes[$ext],1), true);
- }else{
- $ret = array($ext, $mtypes[$ext], false);
+ 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);
}
}