More MIME types

This commit is contained in:
Laurent Destailleur 2009-10-15 02:27:20 +00:00
parent 1514c5a6fa
commit e1c14b9c3e
3 changed files with 42 additions and 12 deletions

View File

@ -70,28 +70,40 @@ function llxHeader() { }
$type = 'application/octet-stream';
if (! empty($_GET["type"])) $type=$_GET["type"];
else $type=dol_mimetype($original_file);
//print 'X'.$type.'-'.$original_file;exit;
// Define attachment (attachment=true to force choice popup 'open'/'save as')
$attachment = true;
// Documents
if (eregi('\.doc$',$original_file)) { $attachment = true; }
if (eregi('\.ppt$',$original_file)) { $attachment = true; }
if (eregi('\.xls$',$original_file)) { $attachment = true; }
if (eregi('\.pdf$',$original_file)) { $attachment = true; }
// Misc
if (eregi('\.sql$',$original_file)) { $attachment = true; }
if (eregi('\.html$',$original_file)) { $attachment = false; }
// Text files
if (eregi('\.txt$',$original_file)) { $attachment = false; }
if (eregi('\.csv$',$original_file)) { $attachment = true; }
if (eregi('\.tsv$',$original_file)) { $attachment = true; }
// Documents MS office
if (eregi('\.doc$',$original_file)) { $attachment = true; }
if (eregi('\.dot$',$original_file)) { $attachment = true; }
if (eregi('\.mdb$',$original_file)) { $attachment = true; }
if (eregi('\.ppt$',$original_file)) { $attachment = true; }
if (eregi('\.xls$',$original_file)) { $attachment = true; }
// Documents Open office
if (eregi('\.odp$',$original_file)) { $attachment = true; }
if (eregi('\.ods$',$original_file)) { $attachment = true; }
if (eregi('\.odt$',$original_file)) { $attachment = true; }
// Misc
if (eregi('\.(html|htm)$',$original_file)) { $attachment = false; }
if (eregi('\.pdf$',$original_file)) { $attachment = true; }
if (eregi('\.sql$',$original_file)) { $attachment = true; }
// Images
if (eregi('\.jpg$',$original_file)) { $attachment = true; }
if (eregi('\.jpeg$',$original_file)) { $attachment = true; }
if (eregi('\.png$',$original_file)) { $attachment = true; }
if (eregi('\.gif$',$original_file)) { $attachment = true; }
if (eregi('\.bmp$',$original_file)) { $attachment = true; }
if (eregi('\.tiff$',$original_file)) { $attachment = true; }
// Calendar
if (eregi('\.vcs$',$original_file)) { $attachment = true; }
if (eregi('\.ics$',$original_file)) { $attachment = true; }
if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false;
//print "XX".$attachment;exit;
// Suppression de la chaine de caractere ../ dans $original_file
$original_file = str_replace("../","/", $original_file);

View File

@ -459,7 +459,7 @@ class FormFile
print "<tr $bc[$var]><td>";
//print "XX".$file['name']; //$file['name'] must be utf8
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
if ($forcedownload) print '&type=application/binary';
//if ($forcedownload) print '&type=application/binary';
print '&file='.urlencode($relativepath.$file['name']).'">';
print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
print dol_trunc($file['name'],$maxlength,'middle');

View File

@ -168,24 +168,42 @@ function dol_compare_file($a, $b)
function dol_mimetype($file)
{
$mime='application/octet-stream';
// Text files
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('\.tsv$',$file)) $mime='text/tab-separated-values';
// MS office
if (eregi('\.mdb$',$file)) $mime='application/msaccess';
if (eregi('\.doc$',$file)) $mime='application/msword';
if (eregi('\.dot$',$file)) $mime='application/msword';
if (eregi('\.xls$',$file)) $mime='application/vnd.ms-excel';
if (eregi('\.ppt$',$file)) $mime='application/vnd.ms-powerpoint';
// Open office
if (eregi('\.odp$',$file)) $mime='application/vnd.oasis.opendocument.presentation';
if (eregi('\.ods$',$file)) $mime='application/vnd.oasis.opendocument.spreadsheet';
if (eregi('\.odt$',$file)) $mime='application/vnd.oasis.opendocument.text';
// Mix
if (eregi('\.(html|htm)$',$file)) $mime='text/html';
if (eregi('\.pdf$',$file)) $mime='application/pdf';
if (eregi('\.xls$',$file)) $mime='application/x-msexcel';
if (eregi('\.sql$',$file)) $mime='text/plain';
if (eregi('\.(sh|ksh|bash)$',$file)) $mime='text/plain';
// Images
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';
// Calendar
if (eregi('\.vcs$',$file)) $mime='text/calendar';
if (eregi('\.ics$',$file)) $mime='text/calendar';
// Other
if (eregi('\.torrent$',$file)) $mime='application/x-bittorrent';
// Audio
if (eregi('\.(mp3|ogg|au)$',$file)) $mime='audio';
// Video
if (eregi('\.(avi|mvw|divx|xvid)$',$file)) $mime='video';
// Archive
if (eregi('\.(zip|rar|gz|tgz|z|cab|bz2)$',$file)) $mime='archive';
return $mime;
}