diff --git a/htdocs/document.php b/htdocs/document.php index 58086e0bef0..cb4ed2e299a 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -54,6 +54,7 @@ else require("./main.inc.php"); // master.inc.php is included in main.inc.php } +require_once(DOL_DOCUMENT_ROOT.'/lib/files.lib.php'); // C'est un wrapper, donc header vierge @@ -64,19 +65,24 @@ $action = $_GET["action"]; $original_file = urldecode($_GET["file"]); $modulepart = urldecode($_GET["modulepart"]); $urlsource = urldecode($_GET["urlsource"]); -// Define type (attachment=1 to force popup 'save as') -$type = urldecode($_GET["type"]); + +// Define mime type +$type = 'application/octet-stream'; +if (! empty($_GET["type"])) $type=urldecode($_GET["type"]); +else $type=dol_mimetype($original_file); + +// Define attachment (attachment=1 to force popup 'save as') $attachment = true; -if (eregi('\.sql$',$original_file)) { $type='text/plain'; $attachment = true; } -if (eregi('\.html$',$original_file)) { $type='text/html'; $attachment = false; } -if (eregi('\.csv$',$original_file)) { $type='text/csv'; $attachment = true; } -if (eregi('\.pdf$',$original_file)) { $type='application/pdf'; $attachment = true; } -if (eregi('\.xls$',$original_file)) { $type='application/x-msexcel'; $attachment = true; } -if (eregi('\.jpg$',$original_file)) { $type='image/jpeg'; $attachment = true; } -if (eregi('\.png$',$original_file)) { $type='image/jpeg'; $attachment = true; } -if (eregi('\.tiff$',$original_file)) { $type='image/tiff'; $attachment = true; } -if (eregi('\.vcs$',$original_file)) { $type='text/calendar'; $attachment = true; } -if (eregi('\.ics$',$original_file)) { $type='text/calendar'; $attachment = true; } +if (eregi('\.sql$',$original_file)) { $attachment = true; } +if (eregi('\.html$',$original_file)) { $attachment = false; } +if (eregi('\.csv$',$original_file)) { $attachment = true; } +if (eregi('\.pdf$',$original_file)) { $attachment = true; } +if (eregi('\.xls$',$original_file)) { $attachment = true; } +if (eregi('\.jpg$',$original_file)) { $attachment = true; } +if (eregi('\.png$',$original_file)) { $attachment = true; } +if (eregi('\.tiff$',$original_file)) { $attachment = true; } +if (eregi('\.vcs$',$original_file)) { $attachment = true; } +if (eregi('\.ics$',$original_file)) { $attachment = true; } // Suppression de la chaine de caractere ../ dans $original_file $original_file = str_replace("../","/", "$original_file"); diff --git a/htdocs/lib/files.lib.php b/htdocs/lib/files.lib.php index 8959beef7ba..b82552c4b55 100644 --- a/htdocs/lib/files.lib.php +++ b/htdocs/lib/files.lib.php @@ -153,4 +153,31 @@ function dol_compare_file($a, $b) } } +/** + * \brief Return mime type of a file + * \param file Filename + * \return string Return mime type + */ +function dol_mimetype($file) +{ + $mime='application/octet-stream'; + if (eregi('\.txt',$file)) $mime='text/plain'; + if (eregi('\.sql$',$file)) $mime='text/plain'; + if (eregi('\.(html|htm)$',$file)) $mime='text/html'; + if (eregi('\.csv$',$file)) $mime='text/csv'; + if (eregi('\.pdf$',$file)) $mime='application/pdf'; + if (eregi('\.xls$',$file)) $mime='application/x-msexcel'; + if (eregi('\.jpg$',$file)) $mime='image/jpeg'; + if (eregi('\.jpeg$',$file)) $mime='image/jpeg'; + if (eregi('\.png$',$file)) $mime='image/png'; + if (eregi('\.gif$',$file)) $mime='image/gif'; + if (eregi('\.bmp$',$file)) $mime='image/bmp'; + if (eregi('\.tiff$',$file)) $mime='image/tiff'; + if (eregi('\.vcs$',$file)) $mime='text/calendar'; + if (eregi('\.ics$',$file)) $mime='text/calendar'; + if (eregi('\.(mp3|ogg|au)$',$file)) $mime='audio'; + if (eregi('\.(avi|mvw|divx|xvid)$',$file)) $mime='video'; + if (eregi('\.(zip|rar|gz|tgz|z|cab|bz2)$',$file)) $mime='archive'; + return $mime; +} ?> diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index c1de1d8fc9d..385876f91f7 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -1220,7 +1220,7 @@ function img_mime($file,$alt='') if (eregi('\.(png|bmp|jpg|jpeg|gif)',$file)) $mime='image'; if (eregi('\.(mp3|ogg|au)',$file)) $mime='audio'; if (eregi('\.(avi|mvw|divx|xvid)',$file)) $mime='video'; - if (eregi('\.(zip|rar|gz|tgz|z|cab)',$file)) $mime='archive'; + if (eregi('\.(zip|rar|gz|tgz|z|cab|bz2)',$file)) $mime='archive'; if (empty($alt)) $alt='Mime type: '.$mime; $mime.='.png';