[geeklog-cvs] geeklog: - Added a method to set a new option to ignoreMimeType ...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Sun Mar 22 22:52:43 EDT 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/70f99dbc0544
changeset: 6854:70f99dbc0544
user:      blaine Lang <blaine at portalparts.com>
date:      Sun Mar 22 22:52:17 2009 -0400
description:
- Added a method to set a new option to ignoreMimeType Check for upload
- Download will default to allow all available Mime Types
- Added method to add a new MIME type to the download class
$download->addAvailableExtensions(array('pdf' => 'application/pdf'));

diffstat:

2 files changed, 37 insertions(+), 3 deletions(-)
system/classes/downloader.class.php |    7 ++++++-
system/classes/upload.class.php     |   33 +++++++++++++++++++++++++++++++--

diffs (88 lines):

diff -r 9495a2763437 -r 70f99dbc0544 system/classes/downloader.class.php
--- a/system/classes/downloader.class.php	Sun Mar 22 22:45:32 2009 -0400
+++ b/system/classes/downloader.class.php	Sun Mar 22 22:52:17 2009 -0400
@@ -521,7 +521,12 @@
         // OK, file is valid, get file extension
         $pos = strrpos($fileName,'.') + 1;
         $fextension = substr($fileName, $pos);
-        
+
+        // If application has not set the allowedExtensions then initialize to the default
+        if(sizeof($this->_allowedExtensions) == 0) {
+            $this->_allowedExtensions = array_flip($this->_availableExtensions);
+        }
+
         // Send headers.
         if ($this->checkExtension($fextension)) {
             // Display file inside browser.
diff -r 9495a2763437 -r 70f99dbc0544 system/classes/upload.class.php
--- a/system/classes/upload.class.php	Sun Mar 22 22:45:32 2009 -0400
+++ b/system/classes/upload.class.php	Sun Mar 22 22:52:17 2009 -0400
@@ -156,6 +156,10 @@
     * @access private
     */
     var $_imageIndex = 0;                 // Integer
+    /**
+    * @access private
+    */
+    var $_ignoreMimeTest = false;       // Boolean
 
     /**
     * @access private
@@ -992,6 +996,22 @@
     }
 
     /**
+    * If enabled will ignore the MIME checks on file uploads
+    *
+    * @param    boolean     $switch     flag, true or false
+    *
+    */
+    function setIgnoreMimeCheck($switch)
+    {
+        if ($switch) {
+            $this->_ignoreMimeTest = true;
+        } else {
+            $this->_ignoreMimeTest = false;
+        }
+    }
+
+
+    /**
     * This function will print any errors out.  This is useful in debugging
     *
     * @param    boolean     $verbose    whether or not to print immediately or return only a string
@@ -1093,6 +1113,10 @@
     */
     function checkMimeType()
     {
+        if ($this->_ignoreMimeTest) {
+            return true;
+        }
+
         $sc = strpos ($this->_currentFile['type'], ';');
         if ($sc > 0) {
             $this->_currentFile['type'] = substr ($this->_currentFile['type'], 0, $sc);
@@ -1100,7 +1124,12 @@
         $mimeTypes = $this->getAllowedMimeTypes ();
         foreach ($mimeTypes as $mimeT => $extList) {
             if ($mimeT == $this->_currentFile['type']) {
-                $extensions = explode (',', $extList);
+                // Each defined Mime Type can have multiple possible extesions - need to test each
+                if (is_array($extList)) {   // Used if allowedMimeTypes is being defined using the Online Config Manager
+                    $extensions = array_keys($extList);
+                } else {
+                    $extensions = explode (',', $extList);
+                }
                 $fileName = $this->_currentFile['name'];
                 foreach ($extensions as $ext) {
                     $ext = trim($ext);
@@ -1256,7 +1285,7 @@
         }
 
         // Verify allowed mime types exist
-        if (!$this->_allowedMimeTypes) {
+        if (!$this->_ignoreMimeTest AND !$this->_allowedMimeTypes) {
             $this->_addError('No allowed mime types specified, use setAllowedMimeTypes() method');
         }
 



More information about the geeklog-cvs mailing list