Welcome Guest, Not a member yet? Register   Sign In
HTML Template and Its images


I'm a beginer to CI, I used a web template to go on with learning CI. I inserted the contents of that template in a new folder under views and I named it template. The template contains another folder called images and these images is found as a relative path in the CSS file of that template.

Of course the Controller miss these images due to the difference of the path. My question is How to correct this?

[eluser]Damien K.[/eluser]
Make them absolute urls instead.

You mean that changing in the CSS file! Well, By this suggestion you tell that writing something like the following in the CSS file:
background url(http://localhost/ci/application/views/te.../img01.jpg)

Do you agree with me about that may regard a security hole in the application to show its URL? Also it may regard a usability problem, because If I decided to put or access my application from another server or place will lead to miss images too or changing the css every time I want to migrate a server!

[eluser]Colin Williams[/eluser]
You are very confused about relative vs. absolute paths. All paths in your HTML output are relative to the URL. All paths in your CSS, PHP files, etc, are relative to themselves. So, you don't need to use absolute paths if you can maintain the integrity of the relationship of the CSS and image files on the server. And there's no security hole to displaying full URLs. That makes zero sense.

[eluser]Damien K.[/eluser]
Show url? You mean expose the fact that you're using CI?

Regardless, I would suggest to move the images from the template folder to, for example, http://localhost/images/. With this setup, you have no reference to "ci", and furthermore I think you must do it 'cause CI will treat everything after "ci" as controller/function/arguments. Hence, you can never access the images.

Usability? I suggest writing something like this (using your example):
background: url(/ci/application/views/template/images/img01.jpg)

Sorry for my mistake. The problem was in the template file itself when it set the link tag for css:
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
after changing href value to :http://localhost/ci/application/views/template/style.css , every thing gone well. However, you stated that this could not be regarded as a security voluntary. I just need to confirm this information.

[eluser]Colin Williams[/eluser]
You should be able to draw out the logic yourself. I suppose, technically, a hacker would have a slight edge if they had knowledge of at least part of your codebase, the part that is CI. But if you have faith in CI, you shouldn't need to worry. I would equate it to taking a tank and draping it with cloth as an extra security barrier.

Having images and CSS in your CI directory probably isn't a good idea for other reasons, and having your CI files in a publicly accessible location is a security flaw itself.

Colin is right.

Place your CI files above your public directory in the root

For Example if your site is accessed under public_html put them above that in the root.


Place the assets or whatever you want to name it in your public folder.


Thank you for the valuable help.

What about create a seperate controller for handling images?
I don`t think this wil have a effect in terms of speed and performance. Gives you flexibility

class Images extends Controller {

    function Images()
    function view($image = NULL)
      //Base URL
          $url = 'http://localhost/code/system/applications/view/images/';
          header("Content-type: image/jpeg");
    include($url. '$image'.jpg);

In your template or view file simply point to images
<img src="images/dog">

Theme © iAndrew 2016 - Forum software by © MyBB