Ejemplo n.º 1
0
 /**
  * Returns the mime type for the file.
  * If it can't detect it it will return application/octet-stream
  * 
  * @todo rename to contentType
  * @return String 
  */
 public function mimeType()
 {
     $types = file_get_contents(\GO::config()->root_path . 'mime.types');
     if ($this->extension() != '') {
         $pos = stripos($types, ' ' . $this->extension());
         if ($pos) {
             $pos++;
             $start_of_line = \GO\Base\Util\String::rstrpos($types, "\n", $pos);
             $end_of_mime = strpos($types, ' ', $start_of_line);
             $mime = substr($types, $start_of_line + 1, $end_of_mime - $start_of_line - 1);
             return $mime;
         }
     }
     //if($this->exists()){ Don't use exists function becuase MemoryFile returns true but it does not exist on disk
     if (file_exists($this->path())) {
         if (function_exists('finfo_open')) {
             $finfo = finfo_open(FILEINFO_MIME);
             $mimetype = finfo_file($finfo, $this->path());
             finfo_close($finfo);
             return $mimetype;
         } elseif (function_exists('mime_content_type')) {
             return mime_content_type($this->path());
         }
     }
     return 'application/octet-stream';
 }