Beispiel #1
0
 function checkMime($name, $path, $type = null)
 {
     $extension = strtolower(substr(strrchr($name, "."), 1));
     // check file mime type if possible
     if (function_exists('mime_content_type')) {
         if ($mimetype = @mime_content_type($path)) {
             if ($mime = mimeType::getMime($mimetype)) {
                 return in_array($extension, $mime);
             }
         }
     } else {
         if (function_exists('finfo_open')) {
             $finfo = finfo_open(FILEINFO_MIME);
             $mimetype = finfo_file($finfo, $path);
             finfo_close($finfo);
             if ($mime = mimeType::getMime($mimetype)) {
                 return in_array($extension, $mime);
             }
         }
     }
     return false;
 }
Beispiel #2
0
 public function loadSupport($file)
 {
     global $APP_VIEWS;
     /* $file will be an array because it should have been processed by the
      * routing class
      */
     if (is_array($file)) {
         /* Build the actual file name from the array */
         $file_name = '';
         foreach ($file as $bit) {
             $file_name .= $bit . DS;
         }
         $file_name = trim($file_name, DS);
         $file_type = explode('.', $file_name);
         /* Get the filetype from the filename */
         if (is_array($file_type) && count($file_type) > 1) {
             $file_type = end($file_type);
         } else {
             $file_type = '';
         }
         /* If the filename is in $APP_VIEWS then it's good, include it */
         if (in_array($file_name, array_keys($APP_VIEWS)) && !empty($file_type)) {
             $file = $APP_VIEWS[$file_name];
             /* Figure out the mime-type and set our header */
             $mime_type = mimeType::getMimeType($file);
             header('Content-type: ' . $mime_type);
             /* read the file off, this prevents against the browser
              * prompting a download
              */
             readfile($file);
             exit;
         }
     }
 }
Beispiel #3
0
 function checkMimeType($file)
 {
     // check image validity and mime type
     if (preg_match('#\\.(jpeg|jpg|jpe|png|gif|wbmp|bmp|tiff|tif)$#i', $file['name'])) {
         if (getimagesize($file['tmp_name']) === false) {
             return false;
         }
         if (!$this->checkXSS($file)) {
             $this->_result['text'] = JText::_('Invalid File');
             $passed = false;
         }
     }
     if ($this->getEditorParam('editor_validate_mimetype', 0)) {
         // check the mimetype
         require_once dirname(__FILE__) . DS . 'mime.php';
         return mimeType::checkMime($file['name'], $file['tmp_name'], $file['type']);
     }
     return true;
 }