当前位置: 首页>>代码示例>>PHP>>正文


PHP IOHelper::getMimeTypeByExtension方法代码示例

本文整理汇总了PHP中IOHelper::getMimeTypeByExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::getMimeTypeByExtension方法的具体用法?PHP IOHelper::getMimeTypeByExtension怎么用?PHP IOHelper::getMimeTypeByExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOHelper的用法示例。


在下文中一共展示了IOHelper::getMimeTypeByExtension方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderTemplate

 /**
  * Renders a template, and either outputs or returns it.
  *
  * @param mixed $template      The name of the template to load, or a StringTemplate object.
  * @param array $variables     The variables that should be available to the template
  * @param bool  $return        Whether to return the results, rather than output them
  * @param bool  $processOutput
  * @throws HttpException
  * @return mixed
  */
 public function renderTemplate($template, $variables = array(), $return = false, $processOutput = false)
 {
     if (($output = craft()->templates->render($template, $variables)) !== false) {
         if ($processOutput) {
             $output = $this->processOutput($output);
         }
         if ($return) {
             return $output;
         } else {
             // Get the template file's MIME type
             $templateFile = craft()->templates->findTemplate($template);
             $extension = IOHelper::getExtension($templateFile, 'html');
             $mimeType = IOHelper::getMimeTypeByExtension('.' . $extension);
             if (!$mimeType) {
                 $mimeType = 'text/html';
             }
             header('Content-Type: ' . $mimeType . '; charset=utf-8');
             if ($mimeType == 'text/html') {
                 // Are there any head/foot nodes left in the queue?
                 $headHtml = craft()->templates->getHeadHtml();
                 $footHtml = craft()->templates->getFootHtml();
                 if ($headHtml) {
                     if (($endHeadPos = stripos($output, '</head>')) !== false) {
                         $output = substr($output, 0, $endHeadPos) . $headHtml . substr($output, $endHeadPos);
                     } else {
                         $output .= $headHtml;
                     }
                 }
                 if ($footHtml) {
                     if (($endBodyPos = stripos($output, '</body>')) !== false) {
                         $output = substr($output, 0, $endBodyPos) . $footHtml . substr($output, $endBodyPos);
                     } else {
                         $output .= $footHtml;
                     }
                 }
             }
             // Output to the browser!
             echo $output;
             // End the request
             craft()->end();
         }
     } else {
         throw new HttpException(404);
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:55,代码来源:BaseController.php

示例2: sendResource

 /**
  * Sends a resource back to the browser.
  *
  * @param string $path
  *
  * @throws HttpException
  * @return null
  */
 public function sendResource($path)
 {
     if (PathHelper::ensurePathIsContained($path) === false) {
         throw new HttpException(404);
     }
     $cachedPath = $this->getCachedResourcePath($path);
     if ($cachedPath) {
         if ($cachedPath == ':(') {
             // 404
             $realPath = false;
         } else {
             // We've got it already
             $realPath = $cachedPath;
         }
     } else {
         // We don't have a cache of the file system path, so let's get it
         $realPath = $this->getResourcePath($path);
         // Now cache it
         $this->cacheResourcePath($path, $realPath);
     }
     if ($realPath === false || !IOHelper::fileExists($realPath)) {
         throw new HttpException(404);
     }
     // If there is a timestamp and HTTP_IF_MODIFIED_SINCE exists, check the timestamp against requested file's last
     // modified date. If the last modified date is less than the timestamp, return a 304 not modified and let the
     // browser serve it from cache.
     $timestamp = craft()->request->getParam($this->dateParam, null);
     if ($timestamp !== null && array_key_exists('HTTP_IF_MODIFIED_SINCE', $_SERVER)) {
         $requestDate = DateTime::createFromFormat('U', $timestamp);
         $lastModifiedFileDate = IOHelper::getLastTimeModified($realPath);
         if ($lastModifiedFileDate && $lastModifiedFileDate <= $requestDate) {
             // Let the browser serve it from cache.
             HeaderHelper::setHeader('HTTP/1.1 304 Not Modified');
             craft()->end();
         }
     }
     // Note that $content may be empty -- they could be requesting a blank text file or something. It doens't matter.
     // No need to throw a 404.
     $content = IOHelper::getFileContents($realPath);
     // Normalize URLs in CSS files
     $mimeType = IOHelper::getMimeTypeByExtension($realPath);
     if (mb_strpos($mimeType, 'css') !== false) {
         $content = preg_replace_callback('/(url\\(([\'"]?))(.+?)(\\2\\))/', array(&$this, '_normalizeCssUrl'), $content);
     }
     if (!craft()->config->get('useXSendFile')) {
         $options['forceDownload'] = false;
         if (craft()->request->getQuery($this->dateParam)) {
             $options['cache'] = true;
         }
         craft()->request->sendFile($realPath, $content, $options);
     } else {
         craft()->request->xSendFile($realPath);
     }
     // You shall not pass.
     craft()->end();
 }
开发者ID:JamesGibsonUK,项目名称:gibsonlearn,代码行数:64,代码来源:ResourcesService.php

示例3: getMimeType

 /**
  * @return mixed
  */
 public function getMimeType()
 {
     if (!$this->_mimeType) {
         $extension = IOHelper::getExtension($this->getPath(), 'html');
         $this->_mimeType = IOHelper::getMimeTypeByExtension('.' . $extension);
     }
     return $this->_mimeType;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:11,代码来源:HttpRequestService.php


注:本文中的IOHelper::getMimeTypeByExtension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。