CodeIgniter Forums
Image folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Image folder (/thread-8725.html)



Image folder - El Forum - 05-29-2008

[eluser]MrSmith[/eluser]
Hi everybody, I am very new in CodeIgniter. I write a simple webpage and then I confuse how to show images in my web page. I want to create image folder to keep all of images that use to show in the webpage.Where is path in CodeIgniter folder that I should create this folder and how to insert the image to webpage. Thank you


Image folder - El Forum - 05-29-2008

[eluser]EthanSP[/eluser]
[quote author="MrSmith" date="1212058900"]Hi everybody, I am very new in CodeIgniter. I write a simple webpage and then I confuse how to show images in my web page. I want to create image folder to keep all of images that use to show in the webpage.Where is path in CodeIgniter folder that I should create this folder and how to insert the image to webpage. Thank you[/quote]

You create the [images] folder on your [codeigniter] folder, same level as your [system], [user_guide], etc. folders. You put this script in a php file $this->load->view('foo.jpg'); to view a particular image. You put the said php file under the [views] folder within your [system]/[application] folder.


Image folder - El Forum - 05-29-2008

[eluser]poji23[/eluser]
For me I'm not sure if it's good practice but what I do is I create the images folder on the same level as the system folder, and in my views, if I wish to insert the image I use:

<images src='&lt;?=base_url();?&gt;images/pic.gif' />

I think you could also load the image with:

Code:
$image_properties = array(
       'src' => '/images/backend/comment.png',
       'style' => 'float:left;margin-right:10px;',
);


echo(img($image_properties));



Image folder - El Forum - 05-29-2008

[eluser]MrSmith[/eluser]
If I use CSS to load images to webpage like this :

Code:
body{
    background:url(images/bg.gif) repeat-x 0 0 #FDF9EE; color:#4E4628;
    font:normal 14px/19px Arial, Helvetica, sans-serif;
    margin:0; padding:0;}

How can I custom css to refer to the right path of image file.


Image folder - El Forum - 05-29-2008

[eluser]Michael Wales[/eluser]
Quote:How can I custom css to refer to the right path of image file.

It would be the same as always - a relative path to the image, from the CSS file.

For me, folder structure is:
|system
|webroot
|-application
|-assets
|--images
|--css

So, in a view file, I use:
Code:
<img src="&lt;?php echo base_url(); ?&gt;assets/images/logo.png" />

In CSS:
Code:
background:url(../images/logo.png);