Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use hard-coded MIME type list for common types

FileInfo doesn't always return the correct MIME type (especially for
things like HTML and CSS files), so use a hardcoded list of common
extensions.
  • Loading branch information...
commit 9fdecce1daf6e0f18c0a7f11dae2b32870172770 1 parent fa55845
@Daniel15 authored
Showing with 61 additions and 4 deletions.
  1. +2 −0  README.md
  2. +59 −4 class.azureAccessDriver.php
View
2  README.md 100755 → 100644
@@ -4,6 +4,8 @@ AjaXplorer-Azure
AjaXplorer-Azure is a [AjaXplorer](http://www.ajaxplorer.info/) plugin that allows browsing of Azure
Blob Storage. It runs on both Windows and Linux.
+Currently tested on AjaXplorer 3.3.5 but it may work on newer versions
+
Dependencies
============
- [Windows Azure SDK for PHP](http://phpazure.codeplex.com/) (bundled)
View
63 class.azureAccessDriver.php 100755 → 100644
@@ -388,9 +388,6 @@ private function upload($httpVars, $fileVars, $dir, $selection)
{
$pathinfo = self::splitContainerNamePath($dir);
- // fileinfo is used to get MIME type of uploaded file
- $fileinfo = new finfo(FILEINFO_MIME_TYPE);
-
foreach ($fileVars as $boxName => $boxData)
{
// Skip data that isn't files we want
@@ -409,7 +406,8 @@ private function upload($httpVars, $fileVars, $dir, $selection)
// Save the file into blob storage
$this->storage->putBlob($pathinfo->container, $pathinfo->pathWithSlash . $filename, $boxData['tmp_name'], array(), null, array(
- 'Content-Type' => $fileinfo->file($boxData['tmp_name']),
+ 'Content-Type' => self::getContentTypeFile($boxData['name'], $boxData['tmp_name']),
+ // TODO: Make this customisable?
'Cache-Control' => 'public, max-age=2592000',
));
@@ -555,5 +553,62 @@ private static function splitContainerNamePathFile($path)
return $pathinfo;
}
+
+ private static function getContentTypeFile($filename, $uploadPath)
+ {
+ $extension = strrchr($filename, '.');
+
+ // Common extensions
+ switch ($extension)
+ {
+ case '.jpeg':
+ case '.jpg':
+ return 'image/jpeg';
+ case '.gif':
+ return 'image/gif';
+ case '.png':
+ return 'image/x-png';
+ case '.tif':
+ return 'image/tiff';
+ case '.html':
+ case '.htm':
+ return 'text/html';
+ case '.txt':
+ return 'text/plain';
+ case '.css':
+ return 'text/css';
+ case '.js':
+ return 'text/javascript';
+ case '.rtf':
+ return 'text/richtext';
+ case '.pub':
+ return 'application/vnd.ms-publisher';
+ case '.doc':
+ case '.docx':
+ return 'application/msword';
+ case '.ppt':
+ case '.pptx':
+ return 'application/vnd.ms-powerpoint';
+ case '.xls':
+ case '.xlsx':
+ return 'application/vnd.ms-excel';
+ case '.pdf':
+ return 'application/pdf';
+ case '.woff':
+ return 'font/x-woff';
+ case '.ttf':
+ return 'font/ttf';
+ case '.otf':
+ return 'font/otf';
+ case '.eot':
+ return 'application/vnd.ms-fontobject';
+ case '.svg':
+ return 'image/svg+xml';
+ default:
+ // Not special cased, so use FileInfo extension to get content type
+ $fileinfo = new finfo(FILEINFO_MIME_TYPE);
+ return $fileinfo->file($uploadPath);
+ }
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.