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

[eluser]saidbakr[/eluser]
Hello,

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?
#2

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

[eluser]saidbakr[/eluser]
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!
#4

[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.
#5

[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)
#6

[eluser]saidbakr[/eluser]
Sorry for my mistake. The problem was in the template file itself when it set the link tag for css:
Code:
<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.
#7

[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.
#8

[eluser]InsiteFX[/eluser]
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.

Assets
css
images
js
etc

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

Enjoy
InsiteFX
#9

[eluser]saidbakr[/eluser]
Thank you for the valuable help.
#10

[eluser]William90[/eluser]
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

Code:
class Images extends Controller {

    function Images()
    {
        parent::Controller();
    }
    
    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
Code:
<img src="images/dog">




Theme © iAndrew 2016 - Forum software by © MyBB