Added default 404 page
This commit is contained in:
52
application/classes/Controller/Media.php
Normal file
52
application/classes/Controller/Media.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides access to rendering media items (javascript, images and css).
|
||||
*
|
||||
* @package Redir
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Media extends Controller {
|
||||
/**
|
||||
* This action will render all the media related files for a page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function action_get() {
|
||||
// Get the file path from the request
|
||||
$file = $this->request->param('file');
|
||||
|
||||
// Find the file extension
|
||||
$ext = pathinfo($file,PATHINFO_EXTENSION);
|
||||
|
||||
// Remove the extension from the filename
|
||||
$file = substr($file,0,-(strlen($ext)+1));
|
||||
$f = '';
|
||||
|
||||
// If our file is pathed with session, our file is in our session.
|
||||
if ($fd = Session::instance()->get_once($this->request->param('file'))) {
|
||||
$this->response->body($fd);
|
||||
|
||||
// If not found try a default media file
|
||||
} elseif ($f = Kohana::find_file('media',$file,$ext)) {
|
||||
// Send the file content as the response
|
||||
$this->response->body(file_get_contents($f));
|
||||
|
||||
} else {
|
||||
// Return a 404 status
|
||||
$this->response->status(404);
|
||||
}
|
||||
|
||||
// Generate and check the ETag for this file
|
||||
$this->check_cache(sha1($this->response->body()));
|
||||
|
||||
// Set the proper headers to allow caching
|
||||
$this->response->headers('Content-Type',File::mime_by_ext($ext));
|
||||
$this->response->headers('Content-Length',(string)$this->response->content_length());
|
||||
$this->response->headers('Last-Modified',date('r',$f ? filemtime($f) : time()));
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user