Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4 installation and img directory
#1

I have installed Codeigniter 4 in the xampp   c:\xampp\htdocs\

I have added a virtual host in the httpd-vhosts  under C:\xampp\apache\conf\extra

I have also added  127.0.0.1 kpi.local in the etc/host
Code:
<VirtualHost *:80>
    DocumentRoot "C:\xampp\htdocs\kpi\public"
    ServerName kpi.local
    <Directory "C:\xampp\htdocs\kpi\public">
        Order allow,deny
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>


My codeigniter4 project name is kpi. everything is working fine and my project is running absolutely fine as http://kpi.local

but i have img folder in my public directory and base url in config is defined as http://kpi.local but when i check the html source code it is shown as http://kpi.local/public/img/logo.png. but unfortunately logo.png does not appear in the page and img directory doesn't seems to be accessible to my project and when i click on the above link it says 404 file not found.

Kindly help me how can allow images to be perfectly displayed in my project.

Thanks
Reply
#2

It should work. Do you use base_url() to generate the image’s url?
I’d say, double-check your config files (CI and virtual host) and your view files, and restart your web server.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

(This post was last modified: 04-15-2020, 03:45 AM by InsiteFX.)

This is how my Virtual Host is setup, change public_htnl to public.

Code:
#--------------------------------------------------------------
# HTTP:
#--------------------------------------------------------------
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/ci4admin/public_html"
    ServerName ci4admin.local
    ServerAlias ci4admin.local
    <Directory "C:/xampp/htdocs/ci4admin/public_html">
        Order allow,deny
        Allow from all
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

#--------------------------------------------------------------
# HTTPS:
#--------------------------------------------------------------
<VirtualHost *:443>
    DocumentRoot "C:/xampp/htdocs/ci4admin/public_html"
    ServerName ci4admin.local
    ServerAlias ci4admin.local
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
    <Directory "C:/xampp/htdocs/ci4admin/public_html">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

I create an assets folder under the public folder and use the base_url to access it;

Code:
<img src="<?= base_url('assets/images/someimage.png');?>" alt="Smiley face">

Give that a try.
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 04-12-2020, 08:48 PM by John_Betong.)

@itrashulk
> shown as http://kpi.local/public/img/logo.png. but unfortunately logo.png does not appear in the page and img directory doesn't seems to be accessible to my project and when i click on the above link it says 404 file not found.

A couple of points to check:

1. usually online server is Apache2 and filenames, directories, etc are CaSeSenSitive.

2. rendering the page and browsing/viewing the content (right-click, view content) will show the full path of the image. Copy the full path and paste into a new browser window. This should show the image unless the directory and image are read only.
Reply
#5

It's working.

Thanks
Reply
#6

@itsrahulk,,
> It's working.

Thanks for letting us know.

For the benefit of other users who may experience the same problem please detail the necessary changes.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB