ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Not able to display images

October 06, 2009 5:50pm

Subscribe [7]
  • #1 / Oct 06, 2009 5:50pm

    shinokada

    144 posts

    I am using XAMPP and created a directroy htdocs/codeigniter_shopping.

    Inside that directroy I have an image directory same level as system directory.

    htdocs/codeigniter_shopping/images
    htdocs/codeigniter_shopping/system

    I have .htaccess as follows.

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
    RewriteRule ^(.*)$ index.php/$1 [L]

    I have stored paths to images in database.

    /images/dummy-thumb.jpg

    However it does not display any image.

    I am able to see an image in the following URL.

    http://127.0.0.1/codeigniter_shopping/images/dummy-thumb.jpg

    So I tried ../images/dummy-thumb.jpg, images/dummy-thumb.jpg etc but none of them worked.

    I am hoping if someone can give me ideas how to store the path to image.

    Or do I need to change any .htaccess or not.

    Thanks in advance.

  • #2 / Oct 06, 2009 6:59pm

    jedd

    2089 posts

    However it does not display any image.

    Why not?

    As in - when you look at your page source in your browser, can you determine if the pathing is wrong, or if the tag is wrong, or if .. (etc - you get the idea).


    You could use something like this:

    $img_array = array ("src"=> "/codeigniter_shopping/images/dummy-thumb.jpg",  "width" => "180px", "border"=>"0", "alt"=>"some text");
    echo anchor (img($img_array ));
  • #3 / Oct 06, 2009 8:09pm

    Colin Williams

    2601 posts

    How is it that 60% - 70% of “CodeIgniter problems” people experience is something as simple as resolving paths. Take a step back people. Learn the fundamentals.

  • #4 / Oct 06, 2009 8:25pm

    Zack Kitzmiller

    175 posts

    How is it that 60% - 70% of “CodeIgniter problems” people experience is something as simple as resolving paths. Take a step back people. Learn the fundamentals.

    *clap* *clap*

    Show us the code the CI is outputting to the browser. Then maybe we can help you.

  • #5 / Oct 07, 2009 2:58am

    shinokada

    144 posts

    When I see http://127.0.0.1/codeigniter_shopping/, it shows images by using the image path images/dummy-thumb.jpg.
    However when I visit http://127.0.0.1/codeigniter_shopping/welcome/index or
    http://127.0.0.1/codeigniter_shopping/welcome/product/1
    no images will shown.

    The links are working.

    It seems that I have to add http://127.0.0.1/codeigniter_shopping/images/dummy-thumb.jpg to show images.

    <div class='productlisting'>images/dummy-thumb.jpg
    
    <h4>Dress 1</h4>
    <p><a href="http://127.0.0.1/codeigniter_shopping/welcome/product/10" title="see details">see details</a><br><br />
    <a href="http://127.0.0.1/codeigniter_shopping/welcome/cart/10" title="add to cart">add to cart</a><br />
    </div>

  • #6 / Oct 07, 2009 3:33am

    Colin Williams

    2601 posts

  • #7 / Oct 07, 2009 4:17am

    InsiteFX

    6819 posts

    site_url()
    
    Returns your site URL, as specified in your config file. The index.php file 
    (or whatever you have set as your site index_page in your config file) 
    will be added to the URL, as will any URI segments you pass to the function.
    
    You are encouraged to use this function any time you need to generate a local URL
    so that your pages become more portable in the event your URL changes.
    
    Segments can be optionally passed to the function as a string or an array.
    
    READ CodeIgniter user guide.

    Enjoy
    InsiteFX

  • #8 / Oct 07, 2009 4:29am

    shinokada

    144 posts

    Thanks to InsiteFX for a constructive reply.

    I thought the same thing and I experimented to find out all the path and the below is the results.

    The siteurl() gives with index.php at the end, so I will test it with baseurl.

    Or I will define the path to images folder in config file to use it.

    Interesting thing is that CI shows BASEPATH as C:\xampp\htdocs\ci_day6/system/ in XAMPP.

    This means BASEPATH in windows will not work. I suggest to check index.php.

    Basepath: C:\xampp\htdocs\ci_day6/system/
    Apppath: application/
    Ext: .php
    Fcpath: C:\xampp\htdocs\ci_day6\index.php
    Self: index.php
    baseurl: <a href="http://127.0.0.1/ci_day6/">http://127.0.0.1/ci_day6/</a>
    site_url(): <a href="http://127.0.0.1/ci_day6/index.php">http://127.0.0.1/ci_day6/index.php</a>
    current_url(): <a href="http://127.0.0.1/ci_day6/index.php/welcome">http://127.0.0.1/ci_day6/index.php/welcome</a>
    uri_string(): /welcome
    index_page(): index.php
    realpath(__FILE__): C:\xampp\htdocs\ci_day6\application\views\welcome_message.php
    realpath(dirname(__FILE__)): C:\xampp\htdocs\ci_day6\application\views
    realpath(dirname(__FILE__)): C:\xampp\htdocs\ci_day6\application\views/
    str_replace: C:/xampp/htdocs/ci_day6/application/views
    getcwd(), current working directory: C:\xampp\htdocs\ci_day6
  • #9 / Oct 07, 2009 9:48am

    InsiteFX

    6819 posts

    You can fix that problem by using this code, I did not write this several other users on the forum here wrote it.

    Place in application/config/constants.php
    
    /*
    |--------------------------------------------------------------------------
    | Docment root folders
    |--------------------------------------------------------------------------
    |
    | These constants use existing location information to work out web root, etc.
    |
    */
    
    // Base URL (keeps this crazy sh*t out of the config.php
    if (isset($_SERVER['HTTP_HOST']))
    {
        $base_url  = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
        $base_url .= '://'. $_SERVER['HTTP_HOST'];
        $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
    
        // Base URI (It's different to base URL)
        $base_uri = parse_url($base_url, PHP_URL_PATH);
    
        if (substr($base_uri, 0, 1) != '/')
        {
            $base_uri = '/'.$base_uri;
        }
    
        if (substr($base_uri, -1, 1) != '/')
        {
            $base_uri .= '/';
        }
    }
    else
    {
        $base_url = 'http://localhost/';
        $base_uri = '/';
    }
    
    // Define these values to be used later on
    define('BASE_URL', $base_url);
    define('BASE_URI', $base_uri);
    define('APPPATH_URI', BASE_URI.APPPATH);
    define('ASSETS_URL', $base_url."assets/");
    define('CSS_URL', ASSETS_URL."css/");
    define('IMAGE_URL', ASSETS_URL."images/");
    define('JS_URL', ASSETS_URL."js/");
    define('UPLOAD_URL', ASSETS_URL."upload/");
    define('DOWNLOAD_URL', ASSETS_URL."download/");
    
    
    // We dont need these variables any more
    unset($base_uri, $base_url);

    I have modified it to use more constans.

    Enjoy
    InsiteFX

  • #10 / Oct 15, 2009 10:02am

    shinokada

    144 posts

    I added the following in the head.

    ...
    <base href="<?=base_url();?>">
    ...


    Then all the links work.

  • #11 / Oct 15, 2009 10:51am

    renownedmedia

    115 posts

    If you ever have problems like this again, right click on your broken image and click view image. This will give you the URL your browser is trying to find the image at. That should be the first step with this sort of problem solving.

    Ideally, install firebug and you see things like this lit up in red!

  • #12 / Nov 01, 2009 9:46pm

    doubleplusgood

    199 posts

    XAMPP has tripped me up a few times with paths. I develop at home on my Mac and things like using <?=site_url(’‘)?> work perfectly in links for images/styles and so on, but transfer to a Windows computer and XAMPP (when I’m doing my day job) and the same code no longer works. Even when you view source, it includes the <?=site_url(’‘)?> in the links. Very odd - as everything else php related works fine; controllers, views etc.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases