CodeIgniter Forums
Cannot display images in CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Cannot display images in CodeIgniter (/showthread.php?tid=88055)

Pages: 1 2 3


Cannot display images in CodeIgniter - ilkin - 07-12-2023

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?


RE: Cannot display images in CodeIgniter - InsiteFX - 07-12-2023

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');?>">



RE: Cannot display images in CodeIgniter - ilkin - 07-13-2023

Unfortunately it does not work either


RE: Cannot display images in CodeIgniter - JustJohnQ - 07-13-2023

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.


RE: Cannot display images in CodeIgniter - ilkin - 07-13-2023

Tried that. They are identical. http://localhost:8080/project-root/assets/images/profile.jpg


RE: Cannot display images in CodeIgniter - JustJohnQ - 07-13-2023

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?


RE: Cannot display images in CodeIgniter - ilkin - 07-13-2023

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.


RE: Cannot display images in CodeIgniter - JustJohnQ - 07-13-2023

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.


RE: Cannot display images in CodeIgniter - ilkin - 07-13-2023

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


RE: Cannot display images in CodeIgniter - kenjis - 07-13-2023

You should put your images in the public folder.

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