當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::mime_by_ext方法代碼示例

本文整理匯總了PHP中File::mime_by_ext方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::mime_by_ext方法的具體用法?PHP File::mime_by_ext怎麽用?PHP File::mime_by_ext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在File的用法示例。


在下文中一共展示了File::mime_by_ext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: action_index

 /**
  * Serve the file to the browser AND cache it for direct access if in STAGING OR PRODUCTION.
  */
 public function action_index()
 {
     $file = $this->request->param('file');
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $path = Kohana::find_file('assets', $file, FALSE);
     if ($path === FALSE) {
         throw HTTP_Exception::factory('404', 'File not found!');
     }
     $dir = DOCROOT . 'assets' . DIRECTORY_SEPARATOR;
     // Set the proper headers for browser caching
     $this->response->headers('content-type', File::mime_by_ext($ext));
     $this->response->headers('last-modified', date('r', filemtime($path)));
     $content = file_get_contents($path);
     $this->response->body($content);
     // Don't cache the assets unless we are in STAGING OR PRODUCTION.
     if (Kohana::$environment >= Kohana::STAGING) {
         return;
     }
     // Only cache for specific extensions.
     if (!in_array($ext, $this->_cache_extensions)) {
         return;
     }
     // Check if assets sub dir exist.
     $parts = explode('/', $file);
     $file = array_pop($parts);
     foreach ($parts as $part) {
         $dir .= $part . DIRECTORY_SEPARATOR;
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     }
     file_put_contents($dir . $file, $content);
 }
開發者ID:modulargaming,項目名稱:core,代碼行數:36,代碼來源:Assets.php

示例2: action_index

 public function action_index()
 {
     $group = $this->request->param('group');
     if (!$group) {
         throw new HTTP_Exception_404();
     }
     $config = Kohana::$config->load('thumb')->get($group);
     if (!$config) {
         throw new HTTP_Exception_404();
     }
     $file = $this->request->param('file');
     if (!$file) {
         throw new HTTP_Exception_404();
     }
     $path = Arr::get($config, 'path', '');
     if (!empty($path)) {
         $path = rtrim($path, '/') . '/';
     }
     $thumb = Thumb::create($group, $path . $file);
     if ($thumb) {
         // Get the extension from the filename
         $ext = strtolower(pathinfo($thumb, PATHINFO_EXTENSION));
         $mime = File::mime_by_ext($ext);
         $this->response->headers('Content-Type', $mime ? $mime : 'image/jpeg');
         $this->response->body(file_get_contents($thumb));
     } else {
         throw new HTTP_Exception_500();
     }
 }
開發者ID:greor,項目名稱:satin-spb,代碼行數:29,代碼來源:thumb.php

示例3: mime

 /**
  * Attempt to get the mime type from a file. This method is horribly
  * unreliable, due to PHP being horribly unreliable when it comes to
  * determining the mime type of a file.
  *
  *     $mime = File::mime($file);
  *
  * @param   string  file name or path
  * @return  string  mime type on success
  * @return  FALSE   on failure
  */
 public static function mime($filename)
 {
     // Get the complete path to the file
     $filename = realpath($filename);
     // Get the extension from the filename
     $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
     if (preg_match('/^(?:jpe?g|png|[gt]if|bmp|swf)$/', $extension)) {
         // Use getimagesize() to find the mime type on images
         $file = getimagesize($filename);
         if (isset($file['mime'])) {
             return $file['mime'];
         }
     }
     if (class_exists('finfo', FALSE)) {
         if ($info = new finfo(defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME)) {
             return $info->file($filename);
         }
     }
     if (ini_get('mime_magic.magicfile') and function_exists('mime_content_type')) {
         // The mime_content_type function is only useful with a magic file
         return mime_content_type($filename);
     }
     if (!empty($extension)) {
         return File::mime_by_ext($extension);
     }
     // Unable to find the mime-type
     return FALSE;
 }
開發者ID:reznikds,項目名稱:Reznik,代碼行數:39,代碼來源:file.php

示例4: action_copy

	/**
	 * When Kohana::$environment is set to Kohana::DEVELOPMENT
	 * the asset will be served from this Controller.
	 * Otherwise the file will be served here once and then
	 * copied to DOCROOT and subsequently served from there.
	 *
	 * @return  void
	 */
	public function action_copy()
	{
		$asset = $this->request->param('asset');
		$last_modified = date(DATE_RFC1123, filemtime($asset));
		
		if ($last_modified === $this->request->headers('if-modified-since'))
		{
			// Speed up the request by sending not modified
			$this->response->status(304);
			return;
		}
	
		if (Publicize::should_copy_to_docroot())
		{
			$uri = $this->request->param('uri');
			Publicize::copy_to_docroot($asset, $uri);
		}

		$extension = pathinfo($asset, PATHINFO_EXTENSION);

		// Bug in 3.2 prevents 'Content-Type' to work as expected -> 'content-type'
		// see: https://github.com/kohana/core/commit/4605ccb6957a7b3a9854792328c937d1db003502
		$this->response->headers(array(
			'content-type'   => File::mime_by_ext($extension),
			'Content-Length' => (string) filesize($asset),
			'Last-Modified'  => $last_modified,
		));

		$this->response->body(file_get_contents($asset));
	}
開發者ID:nexeck,項目名稱:kohana-publicize,代碼行數:38,代碼來源:publicize.php

示例5: action_media

 public function action_media()
 {
     if ($media = $this->request->param('media')) {
         if (preg_match('/\\.swf$/iD', $media)) {
             $file = preg_replace('/^(.+?)\\.swf$/iD', '$1', $media);
             $this->request->headers['Content-Type'] = File::mime_by_ext('swf');
             if ($file = Kohana::find_file('media', $file, 'swf')) {
                 $this->request->response = file_get_contents($file);
             }
             return;
         }
         $this->request->headers['Content-Type'] = File::mime_by_ext('js');
         $file = preg_replace('/^(.+?)\\.js$/iD', '$1', $media);
         if ($file = Kohana::find_file('media', $file, 'js')) {
             $this->request->response = file_get_contents($file);
         }
         /*
         foreach(explode('+', $media) as $file)
         {
         	$file = preg_replace('/^(.+?)\.js$/iD', '$1', $file);
         	
         	if($file = Kohana::find_file('media', $file, 'js'))
         	{
         		$this->request->response .= file_get_contents($file).PHP_EOL;
         	}
         }
         */
     }
 }
開發者ID:TdroL,項目名稱:kohana-jelly-torn,代碼行數:29,代碼來源:torn.php

示例6: before

 public function before()
 {
     $directory = $this->request->directory();
     $controller = $this->request->controller();
     $action = $this->request->action();
     $format = $this->_detect_response_format();
     $mime = File::mime_by_ext($format) ?: 'text/html';
     $this->response->view(['basedir' => $controller, 'directory' => $directory, 'action' => $action, 'format' => $format]);
     $this->response->view->set(['basedir' => $controller, 'directory' => $directory, 'controller' => $controller, 'action' => $action, 'format' => $format, 'request' => $this->request, 'method' => $this->request->method(), 'secure' => $this->request->secure(), 'route' => $this->request->route(), 'route_name' => Route::name($this->request->route()), 'params' => $this->request->param(), 'query' => $this->request->query()]);
     $this->format = $format;
     if ($this->_layout === NULL) {
         $layout = strtolower($controller);
         if ($this->response->view->viewfile_exists($layout, 'layouts')) {
             $this->_layout = $layout;
         } else {
             if ($this->response->view->viewfile_exists($this->_default_layout, 'layouts')) {
                 $this->_layout = $this->_default_layout;
             }
         }
     }
     $this->response->headers('Content-Type', $mime . '; charset=' . Kohana::$charset);
     if ($this->_layout) {
         View::layout($this->_layout);
     }
     $this->_before_action && $this->_call_method_for_action($this->_before_action);
 }
開發者ID:alshabalin,項目名稱:kohana-advanced-view,代碼行數:26,代碼來源:Controller.php

示例7: get_mime_type

 public function get_mime_type()
 {
     $extension = strtolower(pathinfo($this->_filename, PATHINFO_EXTENSION));
     $mime = File::mime_by_ext($extension);
     if (!$mime) {
         $mime = 'application/octet-stream';
     }
     return $mime;
 }
開發者ID:ariol,項目名稱:adminshop,代碼行數:9,代碼來源:File.php

示例8: action_media

 public function action_media($file)
 {
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $file = substr($file, 0, -(strlen($ext) + 1));
     if ($file = Kohana::find_file('media', $file, $ext)) {
         $this->request->response = file_get_contents($file);
     } else {
         $this->request->status = 404;
     }
     $this->request->headers['Content-Type'] = File::mime_by_ext($ext);
 }
開發者ID:rlm80,項目名稱:Archive--glue-orm,代碼行數:11,代碼來源:glue.php

示例9: action_token

 /**
  * This action issues access and refresh tokens and is called only
  * by the 3rd party. All output should be JSON.
  *
  * You DO NOT need to extend/replace this action.
  */
 public function action_token()
 {
     $this->response->headers('Content-Type', File::mime_by_ext('json'));
     try {
         // Attempt to issue a token
         $this->response->body($this->_oauth->token());
     } catch (OAuth2_Exception $e) {
         // Something went wrong, lets give a formatted error
         $this->response->status(400);
         $this->response->body($e->getJsonError());
     }
 }
開發者ID:rafi,項目名稱:kohana-oauth2,代碼行數:18,代碼來源:endpoints.php

示例10: action_img

 public function action_img($filename, $ext)
 {
     if (self::check(300) === FALSE) {
         self::set(300);
     }
     $info = pathinfo($filename);
     $file = Kohana::find_file('views/images', basename($info['basename']), $ext);
     if (!$file) {
         throw new Kohana_Exception("No such file or directory (:filename)", array('filename' => "{$filename}.{$ext}"));
     }
     $this->request->send_file($file, FALSE, array('inline' => 1, 'mime_type' => File::mime_by_ext($ext)));
 }
開發者ID:halkeye,項目名稱:tops,代碼行數:12,代碼來源:static.php

示例11: get_response

 /**
  * Generate a Response for the 404 Exception.
  * 
  * @return Response
  */
 public function get_response()
 {
     $ext = pathinfo(Request::current()->url(), PATHINFO_EXTENSION);
     $mimetype = FALSE;
     if ($ext and !($mimetype = File::mime_by_ext($ext))) {
         $mimetype = 'application/octet-stream';
     }
     if ($mimetype) {
         return Response::factory()->headers('content-type', $mimetype)->status(404);
     } else {
         return parent::get_response();
     }
 }
開發者ID:ZerGabriel,項目名稱:cms-1,代碼行數:18,代碼來源:404.php

示例12: action_media

 public function action_media()
 {
     $file = $this->request->param('file');
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $file = substr($file, 0, -(strlen($ext) + 1));
     if ($file = Kohana::find_file('media', $file, $ext)) {
         $this->response->check_cache(sha1($this->request->uri()) . filemtime($file), $this->request);
         $this->response->body(file_get_contents($file));
         $this->response->headers('content-type', File::mime_by_ext($ext));
         $this->response->headers('last-modified', date('r', filemtime($file)));
     } else {
         throw new HTTP_Exception_404('File not found.');
     }
 }
開發者ID:retio,項目名稱:kohana-leaflet,代碼行數:14,代碼來源:leaflet.php

示例13: action_file

 public function action_file()
 {
     $request = Request::instance();
     $file = $request->param('file');
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $file = substr($file, 0, -(strlen($ext) + 1));
     if ($file = Kohana::find_file('media', $file, $ext)) {
         $request->response = file_get_contents($file);
     } else {
         Kohana::$log->add(Kohana::ERROR, 'Admin media controller error while loading file, ' . $file);
         $request->status = 404;
     }
     $request->headers['Content-Type'] = File::mime_by_ext($ext);
 }
開發者ID:vimofthevine,項目名稱:kohana-admin,代碼行數:14,代碼來源:media.php

示例14: get_response

 public function get_response()
 {
     $ext = pathinfo(Request::current()->url(), PATHINFO_EXTENSION);
     $mimetype = FALSE;
     if ($ext and !($mimetype = File::mime_by_ext($ext))) {
         $mimetype = 'application/octet-stream';
     }
     if ($mimetype and $mimetype !== 'text/html') {
         return Response::factory()->headers('content-type', $mimetype)->status(404);
     }
     if (($page = Model_Page_Front::findByField('behavior_id', 'page_not_found')) !== FALSE) {
         return Request::factory($page->url)->query('message', $this->message)->execute()->status(404);
     }
     throw new HTTP_Exception_404('Something went wrong');
 }
開發者ID:ZerGabriel,項目名稱:cms-1,代碼行數:15,代碼來源:404.php

示例15: action_img

 public function action_img($filename = null)
 {
     if (!$filename) {
         throw new Kohana_Exception("No such file or directory");
     }
     if (Kohana_Core::$environment != Kohana::DEVELOPMENT && self::check(300) === FALSE) {
         self::set(300);
     }
     $info = pathinfo($filename);
     $ext = $info['extension'];
     $filename = $info['filename'];
     $file = Kohana::find_file('views/images', basename($info['basename'], ".{$ext}"), $ext);
     if (!$file) {
         throw new Kohana_Exception("No such file or directory (:filename)", array('filename' => "{$filename}.{$ext}"));
     }
     $this->response->send_file($file, FALSE, array('inline' => 1, 'mime_type' => File::mime_by_ext($ext)));
 }
開發者ID:halkeye,項目名稱:kohana-static,代碼行數:17,代碼來源:static.php


注:本文中的File::mime_by_ext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。