Cml\Http\Response::sendContentTypeBySubFix PHP Method

sendContentTypeBySubFix() public static method

通过后缀名输出contentType
public static sendContentTypeBySubFix ( string $subFix = 'html' )
$subFix string
    public static function sendContentTypeBySubFix($subFix = 'html')
    {
        $mines = ['html' => 'text/html', 'htm' => 'text/html', 'shtml' => 'text/html', 'css' => 'text/css', 'xml' => 'text/xml', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'js' => 'application/x-javascript', 'atom' => 'application/atom+xml', 'rss' => 'application/rss+xml', 'mml' => 'text/mathml', 'txt' => 'text/plain', 'wml' => 'text/vnd.wap.wml', 'jad' => 'text/vnd.sun.j2me.app-descriptor', 'htc' => 'text/x-component', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'wbmp' => 'image/vnd.wap.wbmp', 'ico' => 'image/x-icon', 'jng' => 'image/x-jng', 'bmp' => 'image/x-ms-bmp', 'svg' => 'image/svg+xml', 'svgz' => 'image/svg+xml', 'webp' => 'image/webp', 'doc' => 'application/msword', 'pdf' => 'application/pdf', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'rar' => 'application/x-rar-compressed', 'swf' => 'application/x-shockwave-flash', 'zip' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml', 'mp3' => 'audio/mpeg', 'ogg' => 'audio/ogg', 'm4a' => 'audio/ogg', 'mp4' => 'video/mp4 ', 'wmv' => 'video/x-ms-wmv', 'avi' => 'video/x-msvideo'];
        $mine = isset($mines[$subFix]) ? $mines[$subFix] : 'text/html';
        header("Content-Type:{$mine};charset=utf-8");
    }

Usage Example

Example #1
0
 /**
  * 解析一个静态资源的内容
  *
  */
 public static function parseResourceFile()
 {
     $pathinfo = Route::getPathInfo();
     array_shift($pathinfo);
     $resource = implode('/', $pathinfo);
     if ($GLOBALS['debug'] && CML_IS_MULTI_MODULES) {
         $pos = strpos($resource, '/');
         $file = CML_APP_MODULES_PATH . DIRECTORY_SEPARATOR . substr($resource, 0, $pos) . DIRECTORY_SEPARATOR . Config::get('modules_static_path_name') . substr($resource, $pos);
         if (is_file($file)) {
             Response::sendContentTypeBySubFix(substr($resource, strrpos($resource, '.') + 1));
             exit(file_get_contents($file));
         } else {
             Response::sendHttpStatus(404);
         }
     }
 }
All Usage Examples Of Cml\Http\Response::sendContentTypeBySubFix