1

I'm literally struggling to understand why, as it seems, I can't load any image to my local Codeigniter installation on XAMPP.

I have placed an img folder into the application folder, containing only an image named arrow.png but I cannot access it nor show it on my views.

I have the suspect this might be a .htaccess problem but I have tried different solutions with no success. This is what I have at the moment:

Options FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

In my config PHP I've edited of course:

$config['index_page'] = '';

In my view called ordine.php I called my image like this:

<img src="<?php echo base_url("img/arrow.png"); ?>" title="Go to Top" alt="Go to Top"/>

The generated URL seems right but the image doesn't shows. If I go directly on that link, I get a 404 error.

http://localhost/clientname/img/arrow.png

EDIT: Could it be something with my httpd.conf apache file, set up as the following?

Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"

<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Thank you in advance for any suggestions and help about this.

wiredmark
  • 1,098
  • 6
  • 26
  • 44

3 Answers3

2

I have fixed the problem myself, after an hard search. It all turned out to be OS X permissions not allowing me to see the images in particolar subfolders. What I had to do is written on this post.

Thank you to anyone who put efforts to try to help me out - with this kind of problems, is always quite hard to understand if its a local OS problem or webserver problem.

Community
  • 1
  • 1
wiredmark
  • 1,098
  • 6
  • 26
  • 44
1

Check your htaccess file.Whether it has allowed images to load in the webpage.Here i'll put a working htaccess file.Try it..

RewriteBase /clientname/
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

You could also refer to a forum here that has a discussion on CI not able to display images

Guns
  • 2,678
  • 2
  • 23
  • 51
  • 2
    you probably want to replace images with img – Radu Diță Apr 11 '14 at 12:27
  • @hades2510, yes you are right. made the changes. Thanks! – Guns Apr 11 '14 at 12:28
  • Nothing to do. Tried to change my htaccess file like yours and nothing changes. By the way, I'm speaking about the htaccess located in the root of Codeigniter, the one inside the /application folder just contains "Deny from all" – wiredmark Apr 11 '14 at 12:30
  • Still no luck unfortunately. However now im getting a 404 Error page from Codeigniter, not the normal one from the webserver – wiredmark Apr 11 '14 at 12:37
  • what is the relative path for the image – Guns Apr 11 '14 at 12:42
  • Well the image is placed in xampp/htdocs/clientname/application/img/ so it should be just /img/ I guess – wiredmark Apr 11 '14 at 12:43
  • and does this url `http://localhost/clientname/img/arrow.png` in browser render correctly? – Guns Apr 11 '14 at 12:45
  • Nope. I get 404 Page Not Found. – wiredmark Apr 11 '14 at 12:46
  • can you try `http://localhost/clientname/application/img/arrow.png` and post if that worked – Guns Apr 11 '14 at 12:47
  • This time I get a 403 error from the webserver - as it found the file, but I cannot access it I think – wiredmark Apr 11 '14 at 12:48
  • did you edit anything in the index.php file in the root directory? – Guns Apr 11 '14 at 12:49
  • can you move the img folder out of the application directory and to the root directory and try to access it with url `http://localhost/clientname/img/arrow.png` – Guns Apr 11 '14 at 12:51
  • remove any .htaccess files that are available in img folder and see if you are accessing the right url. Just to confirm and have a double check – Guns Apr 11 '14 at 12:53
  • You know what? I removed the .htaccess (containing the code you gave me) and I keep getting the 403 error.... – wiredmark Apr 11 '14 at 12:55
  • you do not have to remove the .htaccess from the root folder. You have to check if any .htaccess is available in img folder that we copied to the root directory and if available, remove the .htaccess only from img folder – Guns Apr 11 '14 at 12:58
  • Oh, ok. No, anyways, no .htaccess files in the img folder. Just the arrow.png itself – wiredmark Apr 11 '14 at 12:58
  • and can you confirm you have 1. img folder having arrow.png in the root directory 2. Calling the url http://localhost/clientname/img/arrow.png – Guns Apr 11 '14 at 13:01
  • Yes I confirm both 100%. Could it be maybe something with my apace httpd.conf file? I edited the main post – wiredmark Apr 11 '14 at 13:03
  • is the folder name `img` or `Img`? since unix is case sensitive – Guns Apr 11 '14 at 13:06
  • can you add `RewriteBase /clientname/` within your .htaccess as i edited in my answer and try – Guns Apr 11 '14 at 13:09
  • Also added a link [Not Able to Display Images](http://ellislab.com/forums/viewthread/131236) which might help – Guns Apr 11 '14 at 13:13
  • Nothing different happening, I'm starting to think to reinstall Codeigniter into a different folder or something else - since im going totally desperate – wiredmark Apr 11 '14 at 13:14
  • can you check the link i have posted – Guns Apr 11 '14 at 13:14
  • Also, [this](http://ellislab.com/forums/viewthread/131236/#652268) solution looks promising – Guns Apr 11 '14 at 13:16
  • Just checked it but its not my case – wiredmark Apr 11 '14 at 13:17
  • Mine is not a problem of links, mine is a problem that I cant access images not even by inserting their URL directly in the browser – wiredmark Apr 11 '14 at 13:17
  • I fixed it, read my answer. Thanks a lot for your help - it helped me to focalize the problem and understand it was not CI config's related. – wiredmark Apr 11 '14 at 13:24
0
         <?php echo base_url("/img/arrow.png"); ?>

Try this.

user983983
  • 158
  • 1
  • 2
  • 11
  • Doesn't do the trick, the URL generated is just the same: http://localhost/clientname/img/arrow.png and it should be correct but I still get the damn 404 error. "The page you requested was not found." – wiredmark Apr 11 '14 at 12:40
  • I have tried and it doesn't. I can't even access directly the file from my browser! @user983983 – wiredmark Apr 11 '14 at 13:05
  • please read the question carefully before answering, op already say that "I have placed an img folder into the application folder" your answer will output relative to index.php – Adi Prasetyo Jul 03 '16 at 19:16