From 62c5501fb1be864b1e319025393ef6d26c960b93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Aug 2010 16:26:55 +0000 Subject: [PATCH] Enhance mime detection --- htdocs/lib/files.lib.php | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php index ae42eb2e814..1a0a8955f78 100644 --- a/htdocs/lib/files.lib.php +++ b/htdocs/lib/files.lib.php @@ -172,28 +172,28 @@ function dol_mimetype($file,$default='application/octet-stream',$shortmime=0) // Text files if (preg_match('/\.txt$/i',$file)) $mime='text/plain'; - if (preg_match('/\.rtx$/i',$file)) $mime='text/richtext'; + if (preg_match('/\.rtx$/i',$file)) $mime='text/richtext'; if (preg_match('/\.csv$/i',$file)) $mime='text/csv'; if (preg_match('/\.tsv$/i',$file)) $mime='text/tab-separated-values'; - if (preg_match('/\.(cf|conf|ini|log)$/i',$file)) $mime='text/plain'; - if (preg_match('/\.css$/i',$file)) $mime='text/css'; - // Certificate files - if (preg_match('/\.(crt|cer|key|pub)$/i',$file)) $mime='text/plain'; - // HTML - if (preg_match('/\.(html|htm|shtml)$/i',$file)) $mime='text/html'; - // Languages - if (preg_match('/\.bas$/i',$file)) $mime='text/plain'; - if (preg_match('/\.(c|cpp|h)$/i',$file)) $mime='text/plain'; - if (preg_match('/\.(java|jsp)$/i',$file)) $mime='text/plain'; - if (preg_match('/\.php$/i',$file)) $mime='text/plain'; - if (preg_match('/\.(pl|pm)$/i',$file)) $mime='text/plain'; - if (preg_match('/\.sql$/i',$file)) $mime='text/plain'; - if (preg_match('/\.js$/i',$file)) $mime='text/x-javascript'; - // Open office - if (preg_match('/\.odp$/i',$file)) $mime='application/vnd.oasis.opendocument.presentation'; - if (preg_match('/\.ods$/i',$file)) $mime='application/vnd.oasis.opendocument.spreadsheet'; - if (preg_match('/\.odt$/i',$file)) $mime='application/vnd.oasis.opendocument.text'; - // MS Office + if (preg_match('/\.(cf|conf|ini|log)$/i',$file)) $mime='text/plain'; + if (preg_match('/\.css$/i',$file)) $mime='text/css'; + // Certificate files + if (preg_match('/\.(crt|cer|key|pub)$/i',$file)) $mime='text/plain'; + // HTML + if (preg_match('/\.(html|htm|shtml)$/i',$file)) $mime='text/html'; + // Languages + if (preg_match('/\.bas$/i',$file)) $mime='text/plain'; + if (preg_match('/\.(c|cpp|h)$/i',$file)) $mime='text/plain'; + if (preg_match('/\.(java|jsp)$/i',$file)) $mime='text/plain'; + if (preg_match('/\.php$/i',$file)) $mime='text/plain'; + if (preg_match('/\.(pl|pm)$/i',$file)) $mime='text/plain'; + if (preg_match('/\.sql$/i',$file)) $mime='text/plain'; + if (preg_match('/\.js$/i',$file)) $mime='text/x-javascript'; + // Open office + if (preg_match('/\.odp$/i',$file)) $mime='application/vnd.oasis.opendocument.presentation'; + if (preg_match('/\.ods$/i',$file)) $mime='application/vnd.oasis.opendocument.spreadsheet'; + if (preg_match('/\.odt$/i',$file)) $mime='application/vnd.oasis.opendocument.text'; + // MS Office if (preg_match('/\.mdb$/i',$file)) $mime='application/msaccess'; if (preg_match('/\.doc(x|m)?$/i',$file)) $mime='application/msword'; if (preg_match('/\.dot(x|m)?$/i',$file)) $mime='application/msword'; @@ -202,15 +202,15 @@ function dol_mimetype($file,$default='application/octet-stream',$shortmime=0) if (preg_match('/\.xla(m)?$/i',$file)) $mime='application/vnd.ms-excel'; if (preg_match('/\.pps(m|x)?$/i',$file)) $mime='application/vnd.ms-powerpoint'; if (preg_match('/\.ppt(m|x)?$/i',$file)) $mime='application/x-mspowerpoint'; - // Other - if (preg_match('/\.pdf$/i',$file)) $mime='application/pdf'; + // Other + if (preg_match('/\.pdf$/i',$file)) $mime='application/pdf'; // Scripts - if (preg_match('/\.bat$/i',$file)) $mime='text/x-bat'; - if (preg_match('/\.sh$/i',$file)) $mime='text/x-sh'; - if (preg_match('/\.ksh$/i',$file)) $mime='text/x-ksh'; - if (preg_match('/\.bash$/i',$file)) $mime='text/x-bash'; + if (preg_match('/\.bat$/i',$file)) $mime='text/x-bat'; + if (preg_match('/\.sh$/i',$file)) $mime='text/x-sh'; + if (preg_match('/\.ksh$/i',$file)) $mime='text/x-ksh'; + if (preg_match('/\.bash$/i',$file)) $mime='text/x-bash'; // Images - if (preg_match('/\.ico$/i',$file)) $mime='image/x-icon'; + if (preg_match('/\.ico$/i',$file)) $mime='image/x-icon'; if (preg_match('/\.(jpg|jpeg)$/i',$file)) $mime='image/jpeg'; if (preg_match('/\.png$/i',$file)) $mime='image/png'; if (preg_match('/\.gif$/i',$file)) $mime='image/gif'; @@ -228,9 +228,9 @@ function dol_mimetype($file,$default='application/octet-stream',$shortmime=0) // Archive if (preg_match('/\.(zip|rar|gz|tgz|z|cab|bz2|7z|tar|lzh)$/i',$file)) $mime='archive'; // application/xxx where zzz is zip, ... // Exe - if (preg_match('/\.(exe|com)$/i',$file)) $mime='application'; + if (preg_match('/\.(exe|com)$/i',$file)) $mime='application/octet-stream'; // Exe - if (preg_match('/\.(dll|lib|o|so|a)$/i',$file)) $mime='library'; + if (preg_match('/\.(dll|lib|o|so|a)$/i',$file)) $mime='library'; if ($shortmime) {