Welcome Guest, Not a member yet? Register   Sign In
Cannot display images in CodeIgniter
#1

Hi. I just cannot display an image in CodeIgniter. I am constantly getting 404 response from the server and the image is not displayed: 
Code:
<?= $this->extend('layouts/default') ?>
<?= $this->section('content') ?>


<body>
    <nav class="navbar navbar-light">
        <div class="container">
            <a class="navbar-brand" href="#">Navbar</a>
        </div>
    </nav>
    <div class="presentation container">
        <h1 class="name">Ilkin Shafiyev</h1>
        <div class="info">
            <img src="<?php echo base_url() . 'images/profile.jpg'; ?>" />
        </div>
    </div>
</body>

</html>


<?= $this->endSection() ?>
This is my index.php file, located into the Views folder. The image is located in images folder, which itself is located directly in project-root. I set my baseUrl to project-root folder so the path seems to be right. I tried literally everything, tried display different images, but without any success. Image links from external resources, however seem to work just right. What should I do?
Reply
#2

root
-- public or public_html
---- index.php
---- assets
------ css
------ js
------ images
------ img
------ plugins
------ vendor

then you can access them like this

Code:
<img src="<?= base_url('assets/images/profile.jpg');?>">
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Unfortunately it does not work either
Reply
#4

Use developer tools (F12) to find the exact location of the image which is not being displayed.
Check that against your code and location of the image in you CI installation.
Reply
#5

Tried that. They are identical. http://localhost:8080/project-root/asset...rofile.jpg
Reply
#6

And if you open 
http://localhost:8080/project-root/public/assets/images/profile.jpg
In your browser?
What is your folder structure Where is the app and public folder located?
Reply
#7

I am getting "Can't find a route for 'get: project-root/public/assets/images/profile.jpg'". Folder structure is the following: I have project-root folder, which is the baseUrl. Directly inside that folder is the assets folder with images folder in it. I am trying to access the image from index.php file, which is located in Views folder.
Reply
#8

Did you try InsiteFX suggestion to create an assets folder in the public folder, then add an image folder in assets folder? If only to test if that works.
Reply
#9

Yes I did that exactly - otherwise path would be wrong. But it did not work out. Maybe I should create separate route for the picture? I am a little bit new to CodeIgniter. Excuses in advance
Reply
#10

You should put your images in the public folder.

Code:
root
-- public/
---- index.php
---- assets/
------ images/
-- app/
---- Views/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB