Welcome Guest, Not a member yet? Register   Sign In
Display PNG img in view not working
#1

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 ?
Reply
#2

(This post was last modified: 11-28-2021, 06:51 AM by seunex.)

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

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

(This post was last modified: 11-25-2021, 12:41 PM by captain-sensible.)

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
CMS CI4     I use Arch Linux by the way 




Arch Book
Reply
#5

It works.
Thanks
Reply
#6

glad it worked , maybe post your view code, to help clarify for other new users ?
CMS CI4     I use Arch Linux by the way 




Arch Book
Reply
#7

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
What did you Try? What did you Get? What did you Expect?

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

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.
Reply
#9

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 .
CMS CI4     I use Arch Linux by the way 




Arch Book
Reply




Theme © iAndrew 2016 - Forum software by © MyBB