Ejemplo n.º 1
0
 public static function mimeTypeOfFile($sFile)
 {
     $aMimeTypes = DocumentTypePeer::getMostAgreedMimetypes($sFile);
     return $aMimeTypes[0];
 }
Ejemplo n.º 2
0
 public function mimetypeFor($sId, $sSrc)
 {
     if ($sId && !is_numeric($sId)) {
         $sSrc = $sId;
         $sId = '';
     }
     if ($sSrc) {
         if (($iQSPos = strrpos($sSrc, '?')) !== false) {
             $sSrc = substr($sSrc, 0, $iQSPos);
         }
         $bGetHeadersEnabled = ini_get('allow_url_fopen') == '1';
         if (!StringUtil::startsWith($sSrc, '/') && file_exists(MAIN_DIR . '/' . $sSrc)) {
             //Relative url, assume it’s from the MAIN_DIR_FE
             $aMimeTypes = DocumentTypePeer::getMostAgreedMimetypes(MAIN_DIR . '/' . $sSrc);
             return $aMimeTypes[0];
         } else {
             if ($bGetHeadersEnabled) {
                 if (StringUtil::startsWith($sSrc, '//')) {
                     $sSrc = "http:{$sSrc}";
                 }
                 $aHeaders = @get_headers($sSrc, true);
                 if ($aHeaders && isset($aHeaders['Content-Type'])) {
                     $sContentType = $aHeaders['Content-Type'];
                     if (is_array($sContentType)) {
                         $sContentType = array_pop($sContentType);
                     }
                     $iCharsetLocation = strpos($sContentType, ';');
                     if ($iCharsetLocation !== false) {
                         $sContentType = substr($sContentType, 0, $iCharsetLocation);
                     }
                     return $sContentType;
                 }
             }
         }
     }
     return '';
 }