From 27bf79241161079d1d15f8fe1927682ec562835f Mon Sep 17 00:00:00 2001 From: Tom N Harris Date: Sat, 26 Sep 2009 01:17:46 +0200 Subject: Use all available icons for file links (FS#1759) All PNG and GIF images in the lib/images/fileicons directory will be used for media file links. The conf/mime.conf file continues to restrict which file types may be uploaded. File types not in the configuration list are download-only. darcs-hash:20090925231746-6942e-299a52772f67e265a8702bda3686f495e4337a8f.gz --- inc/confutils.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'inc/confutils.php') 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 */ -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); } } -- cgit v1.2.3