Avatar of breeze351
breeze351

asked on 

Syntax for opening an image in PHP

I'm trying to display a gif for a menu.  This is the same type of problem that I had with the new server.  This code worked on the old one.

<a href="./index.php" class="nof-navButtonAnchor"><img id="NavigationButton1" name="NavigationButton1" height="21" width="137" src="../Autogen/Menu_Hhighlighted_1.gif" border="0" alt="Menu" title="Menu"/></a>

If I copy the file "Menu_Hhilghted_1.gif" to the root and mod the code to rellect that it works.

The directory structure is:
Lansco
  -->Autogen
PHPHTML

Avatar of undefined
Last Comment
Ray Paseur
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I think this is an HTML file path issue, not a PHP problem.

Looks like a different directory structure from the old server.  One way to fix this problem is to use fully qualified absolute URLs.    They don't break.  Another is to analyze the new directory structure, find out where image resources are located (relative to the URL of the document that is having the problem) and write a relative link that works for the new directory structure.

You can use a slash as the first character of the link, and it will be resolved relative to the web root of the host.  So if you know your directory structure that might be an easy way to find the image.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ludofulop
ludofulop

where in the directory structure is placed the (php/html) file that contains that html code ? Maybe src="./Autogen/Menu_Hhighlighted_1.gif"  should do it ?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

If I was me, I'd do it this way.  The single '/' indicates that the file and directory are relative to the root.  I figure if I have to use all those dots, I'm doing something wrong.
<a href="/index.php" class="nof-navButtonAnchor"><img id="NavigationButton1" name="NavigationButton1" height="21" width="137" src="/Autogen/Menu_Hhighlighted_1.gif" border="0" alt="Menu" title="Menu"/></a>

Open in new window

Avatar of breeze351
breeze351

ASKER

That was it. The last site had a root where the subdirectory was.  I have to clean up this code.
Thanks
Glenn
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This hint can make your life easier :-)

You can use a slash as the first character of the link, and it will be resolved relative to the web root of the host.  So if you know your directory structure that might be an easy way to find the image.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo