mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Fix: mime type
This commit is contained in:
parent
7233f8ef0e
commit
c705e1d91f
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user