Thursday, September 22, 2011

How do you code php on menu to go up a folder back to the root directory?

I have a web site with about 7 different folders that when I change the main menu on the index I have to drag the menu to each folder. I am looking for the code to put on the menu that goes in the seperate folders so that it will go up a folder and read the main menu on the index(root directory .. to cut down on all the dragging over in ftp client. HELP!!!

Thanks BruceHow do you code php on menu to go up a folder back to the root directory?
put the menu in the main directory as something like 'menu.html'



and then in the php section of each of your other pages, use this code:



%26lt;?php

readfile(';../menu.html';);

?%26gt;



The readfile command reads some HTML or PHP text and includes it directly in the page. The two periods indicate the parent directory, so this program will go find the menu.html code snippet in the parent directory, and print it in the current page.How do you code php on menu to go up a folder back to the root directory?
The other answer is ok, but if your menu is a PHP page, you might consider the following:



%26lt;?php

include('menu.php');

?%26gt;



BUT....the path of the include is relevant to the php file being used at the time. In order to get around this, you should use.



%26lt;?php include($_SERVER['DOCUMENT_ROOT'] . 'menu.php'; ?%26gt;



Might look scary, but this just refers to your root folder. Change this if your menu is in a different folder. (You may also need to add a trailing slash(/) before the menu, depending on your server config.



You do not want to copy the menu into each folder as it will be a nightmare to update if the menu changes. This way you have one menu in one place that will be used on all files, and using this solution eliminates the need to prefix with '../' or '../../' when working out directory structure.

No comments:

Post a Comment