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

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

Code:
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/im...-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

[eluser]jedd[/eluser]
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:
Code:
$img_array = array ("src"=> "/codeigniter_shopping/images/dummy-thumb.jpg",  "width" => "180px", "border"=>"0", "alt"=>"some text");
echo anchor (img($img_array ));
#3

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

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

[eluser]shinokada[/eluser]
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/im...-thumb.jpg to show images.



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

<h4>Dress 1</h4>
<a href="http://127.0.0.1/codeigniter_shopping/welcome/product/10" title="see details">see details</a><br/>
<a href="http://127.0.0.1/codeigniter_shopping/welcome/cart/10" title="add to cart">add to cart</a>
</div>
#6

[eluser]Colin Williams[/eluser]
http://webdesign.about.com/od/beginningt...40502a.htm
#7

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

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

Code:
Basepath: C:\xampp\htdocs\ci_day6/system/
Apppath: application/
Ext: .php
Fcpath: C:\xampp\htdocs\ci_day6\index.php
Self: index.php
baseurl: http://127.0.0.1/ci_day6/
site_url(): http://127.0.0.1/ci_day6/index.php
current_url(): http://127.0.0.1/ci_day6/index.php/welcome
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

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

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

[eluser]shinokada[/eluser]
I added the following in the head.

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


Then all the links work.




Theme © iAndrew 2016 - Forum software by © MyBB