Welcome Guest, Not a member yet? Register   Sign In
Insert Images
#1

[eluser]Unknown[/eluser]
Hello,

I am new to CodeIgniter. I read the user guide but I think I missed something. How do you insert an image onto a page? I am not sure if I have to create a folder in the view folder or outside. I created a folder and put all the images in it but nothing show up on the page when up loading the images.

Can someone help the baby user.

Thanks
#2

[eluser]CI TaMeR[/eluser]
I have created a helper for that called 'img_helper.php' it has with two functions 'anchor_icon()' and anchor_image() maybe that will help
Code:
function anchor_icon($uri, $image, $title = FALSE)
{
    $site_url = site_url($uri);
    $dir  = rstrstr($image, '/');

    if($title === FALSE){
        $title = ucwords($image); // Upper case words
        $title = str_replace('_',' ', $title);
        $title = str_replace('-',' ', $title);
    }
    $img = '<img src="/img/icon/'.$image.'.png" width="30" alt="'.$title.'" title="'.$title.'" />';
    return '<a href="'.$site_url.'">'.$img.'</a>';
}



function anchor_image($uri = '', $title = '', $attributes = '')
{
    if ( ! is_array($uri))
    {
        $site_url = ( ! preg_match('!^\w+://!i', $uri)) ? site_url($uri) : $uri;
    }
    else
    {
        $site_url = site_url($uri);
    }
    
    if ($title == '')
    {
        $title = $site_url;
    }

    return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
#3

[eluser]gunter[/eluser]
outside is the right answer! so you can load them from http://www.something.com/img/blabla.jpg....
#4

[eluser]Phil Sturgeon[/eluser]
A few methods, gunter is onto one of them. Make yourself a media or assets folder. For example call images like:

A)
Quote:<a href="/media/images/something.gif">

or B)
Quote:<a href="&lt;?=site_url();?&gt;media/images/something.gif">

Option A means your script HAS to be in the root, or option B means you have to have the URL helper loaded at all times. Either is just as good, i personally preffer option A.
#5

[eluser]Michael Wales[/eluser]
I go with option A as well, although a slight variation (same end result).

I create 3 folders at the root level: css, js, and images.




Theme © iAndrew 2016 - Forum software by © MyBB