CodeIgniter Forums
Display PNG img in view not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Display PNG img in view not working (/showthread.php?tid=80639)



Display PNG img in view not working - flav - 11-25-2021

Hi,

I put a PNG image in my public/images folder.
I created a view like below but it doesn't show me my image :
Code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

<div>


      <img src="images/download.png"/>
      <img src="<?php echo base_url('.public/images/download.png');?>">

    </div>

</body>
</html>

What it means ?


RE: Display PNG img in view not working - seunex - 11-25-2021

<?php echo base_url(images/download.png); ?>


RE: Display PNG img in view not working - ikesela - 11-25-2021

is this working (add slash at beginning, read as from based url)
Code:
<img src="/images/download.png"/>



RE: Display PNG img in view not working - captain-sensible - 11-25-2021

play along the lines of

<img src = "<?php echo base_url('images/download/download.png'); ?>" > in a view



the path above should be inside public images->download->download.png

so ypu shouldn't need to quote public


a quick tips is when viewing web page and iimage not showing , go to "view source" in browser and see what the actual path that is being
quoted in view source and if it makes sense


RE: Display PNG img in view not working - flav - 11-26-2021

It works.
Thanks


RE: Display PNG img in view not working - captain-sensible - 11-27-2021

glad it worked , maybe post your view code, to help clarify for other new users ?


RE: Display PNG img in view not working - InsiteFX - 11-28-2021

It's always best to use the base_url with images, because if you change to a new server it will still find them.

root
-- public
  ---- assets
    ------ images --> ( base_url('assets/images/image.png'); )
    ------ etc;
-- app
-- modules
-- system
-- writable


RE: Display PNG img in view not working - flav - 11-29-2021

My code below :
Code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>
<p>My first paragraph.</p>

<div>


<img src="<?php echo FCPATH.'assets/download.png'; ?>"/>
<img src="/assets/download.png"/>

</div>

</body>
</html>
The first image does not work (don't know why ?)
The second one works.


RE: Display PNG img in view not working - captain-sensible - 11-29-2021

i think its do to with controllers and the way data is passed to a view.

So to use base_url() in a view from memory you have to use url helper ; i tend not to remember because what i've done is declare them in the base controller so that they are there in any subsequent controller that extends from the base controller.

Now its no problem echoing out a constant in a controller, but in a view , i guess that would have to be passed, in an appropriate way .