From 60baad48ed44869dc874618440bd3e5bca364b9f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 5 Jan 2012 01:47:00 +0000 Subject: [PATCH] In FSFile: * Added getMimeType() and extensionFromPath() functions. * A few other minor code and comment cleanups. --- includes/filerepo/file/FSFile.php | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/includes/filerepo/file/FSFile.php b/includes/filerepo/file/FSFile.php index 72fddaa57b..40f69c5d4d 100644 --- a/includes/filerepo/file/FSFile.php +++ b/includes/filerepo/file/FSFile.php @@ -68,6 +68,15 @@ class FSFile { return $timestamp; } + /** + * Guess the MIME type from the file contents alone + * + * @return string + */ + public function getMimeType() { + return MimeMagic::singleton()->guessMimeType( $this->path, false ); + } + /** * Get an associative array containing information about * a file with the given storage path. @@ -89,12 +98,11 @@ class FSFile { # get the file extension if ( $ext === true ) { - $i = strrpos( $this->path, '.' ); - $ext = strtolower( $i ? substr( $this->path, $i + 1 ) : '' ); + $ext = self::extensionFromPath( $this->path ); } # mime type according to file contents - $info['file-mime'] = $magic->guessMimeType( $this->path, false ); + $info['file-mime'] = $this->getMimeType(); # logical mime type $info['mime'] = $magic->improveTypeFromExtension( $info['file-mime'], $ext ); @@ -143,6 +151,11 @@ class FSFile { return $info; } + /** + * Exract image size information + * + * @return Array + */ protected function extractImageSizeInfo( array $gis ) { $info = array(); # NOTE: $gis[2] contains a code for the image type. This is no longer used. @@ -179,6 +192,17 @@ class FSFile { return $hash; } + /** + * Get the final file extension from a file system path + * + * @param $path string + * @returns string + */ + public static function extensionFromPath( $path ) { + $i = strrpos( $path, '.' ); + return strtolower( $i ? substr( $path, $i + 1 ) : '' ); + } + /** * Get an associative array containing information about a file in the local filesystem. * @@ -188,7 +212,7 @@ class FSFile { * * @return array */ - static function getPropsFromPath( $path, $ext = true ) { + public static function getPropsFromPath( $path, $ext = true ) { $fsFile = new self( $path ); return $fsFile->getProps( $ext ); } @@ -204,7 +228,7 @@ class FSFile { * * @return false|string False on failure */ - static function getSha1Base36FromPath( $path ) { + public static function getSha1Base36FromPath( $path ) { $fsFile = new self( $path ); return $fsFile->getSha1Base36(); } -- 2.20.1