diff --git a/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc b/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc index d4366f20ecb28e896f8bc2cc1586eb4ce1a897f5..420ebe65ef79a0d3d6333df13968ee3dcb336024 100755 --- a/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc +++ b/src/vitis/vas/rest/ws/vitis/File_downloader.class.inc @@ -153,7 +153,9 @@ class File_downloader extends Vitis { if($bReturnFile){ session_write_close(); - $this->getFile($sPath, end(explode("/", $this->aValues["key"]))); + $sFilename = explode("/", $this->aValues["key"]); + $sFilename = end($sFilename); + $this->getFile($sPath, $sFilename); } } else { @@ -166,7 +168,7 @@ class File_downloader extends Vitis { function getFile($sFilePath, $sFileName) { // Le fichier existe ? if (file_exists($sFilePath)) { - $sContentType = mime_content_type($sFilePath); + $sContentType = $this->getMime($sFilePath); header("Content-Type: " . $sContentType); header("Content-disposition: attachment; filename=\"" . $sFileName . "\""); header('Content-Length: ' . filesize($sFilePath)); @@ -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'; + } + } } ?>