How can I display images with the Codeigniter php framework?
I want to fetch an image from the images
folder inside views
.
I used this code in one of the views
php files:
<img border="0" src="images/hed_05.jpg" width="61" height="133">
But it is not working.
CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications. Why CodeIgniter?
CodeIgniter is still exist but the name of this framework has become synonymous with a low-quality solution that is why we advise you Laravel as a better alternative. Both Laravel and CodeIgniter are open-source PHP framework.
Images, css, javascript, pdfs, xml... anything that is allowed to be accessed directly should not be living in your application directory. You can do it, but you really shouldn't. Create a new folder at the root of your directory for these files, they should not be mixed into your application, for example: in your views
folder.
BASEPATH
is defined at the top of most files, and exit('No direct script access.')
if not./users/login
is not loading files from the directory /users/login
, it probably doesn't even exist. These are just uri segments that the bootstrap uses to know which class, method, and params to use. To get the correct path, either use a forward slash (assuming your app and assets are in the root directory, not a subdirectory) like this:
<img src="/images/myimage.jpg" />
Or your best bet, use an absolute url:
// References your $config['base_url']
<img src="<?php echo site_url('images/myimage.jpg'); ?>" />
Equivalent to:
<img src="http://mydomain.com/images/myimage.jpg" />
There are helpers built into CI that you can optionally use as well, but this is really all you need to know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With