Welcome Guest, Not a member yet? Register   Sign In
Not able to display images

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

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


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.


However it does not display any image.

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

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.

Quote: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 ));

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

[eluser]Zack Kitzmiller[/eluser]
[quote author="Colin Williams" date="1254888549"]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.[/quote]

*clap* *clap*

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

When I see, it shows images by using the image path images/dummy-thumb.jpg.
However when I visit or
no images will shown.

The links are working.

It seems that I have to add to show images.

<div class='productlisting'><img src='images/dummy-thumb.jpg' border='0' class='thumbnail'/>

<h4>Dress 1</h4>
<a href="" title="see details">see details</a><br/>
<a href="" title="add to cart">add to cart</a>

[eluser]Colin Williams[/eluser]


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.


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
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

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 .= '/';
    $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('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.


I added the following in the head.

&lt;base href="&lt;?=base_url();?&gt;"&gt;

Then all the links work.

Theme © iAndrew 2016 - Forum software by © MyBB