Last active
November 2, 2015 20:46
-
-
Save shavidzet/ce945f882aea58912605 to your computer and use it in GitHub Desktop.
Assets-codeigniter.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Assets extends CI_Controller { | |
public function manage($filename='') | |
{ | |
$extensions = array('css','js','jpg','png','gif'); | |
$explode = explode('.', $filename); | |
if (!empty($filename) && count($explode) == 2 //if filename is valid | |
&& in_array($explode[1], $extensions) // if file has a valid extension for asset | |
&& file_exists(dirname(__FILE__). "/../assets/".$explode[1].'/'.$filename)) // if file exists in /application/assets/"extension"/"file"."extension" | |
{ | |
// set file header (detecting by extension) | |
switch ($explode[1]) { | |
case 'css': | |
header("Content-type: text/css; charset: UTF-8"); | |
break; | |
case 'js': | |
header('Content-Type: application/javascript'); | |
break; | |
} | |
echo file_get_contents(dirname(__FILE__). "/../assets/".$explode[1].'/'.$filename); // geting file content | |
} else show_404(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
$route['default_controller'] = 'nav/home'; | |
$route['assets/(:any)/(:any)'] = 'assets/manage/$2'; | |
$route['404_override'] = ''; | |
$route['translate_uri_dashes'] = FALSE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment