Jump to content

Cannot get image to display


crmamx

Recommended Posts

Elaboration:

 

This one will not work yet the image is in the same file (content) as the program.

 

<img src="flag_usa.gif" width="84" height="63" alt="usa flag image" />

 

This one works:

 

<img src="http://bayarearcsociety.com/prototype/content/flag_usa.gif" />

 

I just can't figure it out.

For your index.php page in the prototype folder to display an image in prototype/content/ you would need to use -

 

<img src="content/flag_usa.gif" width="84" height="63" alt="usa flag image" />

 

Edit: Alternatively, you can use a domain_root relative URL -

 

<img src="/prototype/content/flag_usa.gif" />

Thank you so much. It works. This has been driving me crazy.

 

Could you please explain it to me.

 

File structure:

                          prototype----------index/php

                              content---------maincontent.php, flag_usa.gif

                                    images

 

Why is the reference from index.php and not maincontent.php? It seems I am calling it from maincontent.php.

 

In my hundreds of other programs using just plain html if the program and image are in the same file, then I was using the correct src.

 

Don't know if I will make it thru this redesign or not... :'(

I going to assume that you are including the maincontent.php file into index.php?

 

That includes the php code that is in maincontent.php ('content'  just happens to be the path to where php can find the maincontent.php file at) into index.php. When the code is finally executed, the code that was included from maincontent.php is part of index.php and is being executed as part of index.php.

 

Looking at this a slightly different way. The browser requested index.php. It is also the browser that requests the image in the src="..." attribute. The browser has no idea that maincontent.php even exits because the browser only sees the HTML that your index.php file outputs. Any relative URL's in an <img> tag are relative to the page they are on, in this case index.php.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.