Skip to content
Snippets Groups Projects
Commit 8d504164 authored by Armand Bahi's avatar Armand Bahi
Browse files

mime error

parent 6ea8ea52
Branches
Tags
No related merge requests found
...@@ -153,7 +153,9 @@ class File_downloader extends Vitis { ...@@ -153,7 +153,9 @@ class File_downloader extends Vitis {
if($bReturnFile){ if($bReturnFile){
session_write_close(); session_write_close();
$this->getFile($sPath, end(explode("/", $this->aValues["key"]))); $sFilename = explode("/", $this->aValues["key"]);
$sFilename = end($sFilename);
$this->getFile($sPath, $sFilename);
} }
} else { } else {
...@@ -166,7 +168,7 @@ class File_downloader extends Vitis { ...@@ -166,7 +168,7 @@ class File_downloader extends Vitis {
function getFile($sFilePath, $sFileName) { function getFile($sFilePath, $sFileName) {
// Le fichier existe ? // Le fichier existe ?
if (file_exists($sFilePath)) { if (file_exists($sFilePath)) {
$sContentType = mime_content_type($sFilePath); $sContentType = $this->getMime($sFilePath);
header("Content-Type: " . $sContentType); header("Content-Type: " . $sContentType);
header("Content-disposition: attachment; filename=\"" . $sFileName . "\""); header("Content-disposition: attachment; filename=\"" . $sFileName . "\"");
header('Content-Length: ' . filesize($sFilePath)); header('Content-Length: ' . filesize($sFilePath));
...@@ -177,7 +179,87 @@ class File_downloader extends Vitis { ...@@ -177,7 +179,87 @@ class File_downloader extends Vitis {
} }
} }
function getMime($sFilePath, $mode=0){
$mime_types = array(
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'docx' => 'application/msword',
'xlsx' => 'application/vnd.ms-excel',
'pptx' => 'application/vnd.ms-powerpoint',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);
$ext = explode('.', $sFilePath);
$ext = array_pop($ext);
$ext = strtolower($ext);
if(function_exists('mime_content_type') && $mode == 0){
$mimetype = mime_content_type($sFilePath);
return $mimetype;
}elseif(function_exists('finfo_open') && $mode == 0){
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $sFilePath);
finfo_close($finfo);
return $mimetype;
}elseif(array_key_exists($ext, $mime_types)){
return $mime_types[$ext];
}else {
return 'application/octet-stream';
}
}
} }
?> ?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment