seperate mimetype guessing from filename

remotes/origin/stable6
Robin Appelman 13 years ago
parent 81b6cab94f
commit cf7321915d
  1. 34
      lib/helper.php

@ -364,19 +364,12 @@ class OC_Helper {
} }
/** /**
* get the mimetype form a local file * Try to guess the mimetype based on filename
* @param string $path *
* @param string $name
* @return string * @return string
* does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
*/ */
static function getMimeType($path) { static public function getFileNameMimeType($name){
$isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://');
if (@is_dir($path)) {
// directories are easy
return "httpd/unix-directory";
}
if(strpos($path, '.')) { if(strpos($path, '.')) {
//try to guess the type by the file extension //try to guess the type by the file extension
if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') { if(!self::$mimetypes || self::$mimetypes != include 'mimetypes.list.php') {
@ -388,6 +381,23 @@ class OC_Helper {
}else{ }else{
$mimeType='application/octet-stream'; $mimeType='application/octet-stream';
} }
}
/**
* get the mimetype form a local file
* @param string $path
* @return string
* does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
*/
static function getMimeType($path) {
$isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://');
if (@is_dir($path)) {
// directories are easy
return "httpd/unix-directory";
}
$mimeType = self::getFileNameMimeType($path);
if($mimeType=='application/octet-stream' and function_exists('finfo_open') if($mimeType=='application/octet-stream' and function_exists('finfo_open')
and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) { and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)) {
@ -609,7 +619,7 @@ class OC_Helper {
} }
/** /**
* remove all files in PHP /oc-noclean temp dir * remove all files in PHP /oc-noclean temp dir
*/ */
public static function cleanTmpNoClean() { public static function cleanTmpNoClean() {
$tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/'; $tmpDirNoCleanFile=get_temp_dir().'/oc-noclean/';

Loading…
Cancel
Save