CodeIgniter Forums
HTML Template and Its images - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: HTML Template and Its images (/showthread.php?tid=22750)

Pages: 1 2


HTML Template and Its images - El Forum - 09-21-2009

[eluser]saidbakr[/eluser]
Its a great idea. Thank you.


HTML Template and Its images - El Forum - 09-21-2009

[eluser]William90[/eluser]
When using this controller you have to spesify both function name and parameter. like images/view/dog.jpg. This is due to the fact that you cannot give parameters to the index member. Add the following in the routes file to make images/dog.jpg work:

Code:
$route['images/(:any)'] = "images/view/$1";

Also a updated version of the controller.
Code:
function view($image = NULL)
    {
        //Base URL
                $url = 'http://localhost/code/system/application/views/images/';
        $image = str_replace('_','.',$image);
        $extention = substr(strrchr($image,'.'),1);
        
        switch ($extention)
        {
            case 'jpg': $content  = 'jpeg'; break;
            default: $content = $extention;
        }
                
        $path = $url.$image;
        if (!file_exists('system/application/views/images/'.$image))
                   $path = $url.'notfound.jpg';
        
        header("Content-type: image/".$content);
        include($path);
    }