Syntax for opening an image in PHP

breeze351
breeze351 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016

Commented:
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.
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
The double dots indicate the parent folder, so ../Autogen/Menu_Hhighlighted_1.gif will head up one folder from the html page, and then drop down into a folder called Autogen, so your structure would need to look like this.

Root
 |- AutoGen
       - Menu_Hhighlighted_1.gif
 | -HTML Files
       - yourPage.html

You haven't said where you page sits, so I can't help you with specifics. Show us your file structure and we'll sort it out for you :)
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 ?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
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

Author

Commented:
That was it. The last site had a root where the subdirectory was.  I have to clean up this code.
Thanks
Glenn
Most Valuable Expert 2011
Top Expert 2016

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial