Friday 7 October 2011

How can i make a php file load from another directory?

I have a php page (index.php) at the root directoy of my server. Depending on GET variables it shows different things. The problem is that i NEED to use directions like www.mypage.com/someting instead of www.mypage.com/index.php?var=someting



I tried to put an index.php on each directory with this code:

%26lt;?

$var=%26quot;something%26quot;;

include('../index.php');

?%26gt;



It did exacly what i needed, except that it looked for all the images and included files in /something instead of the root



If there is any way to change where it looks for the files WITHOUT modyfing the root index.php it would be perfect.



Or maybe there is some other way to do it. please try to give me a solution that doesnt involve changing all the code in the page.How can i make a php file load from another directory?try chdir(); to change the current directory. you may also use getcwd(); for certain needs.

read following documentation

http://ca.php.net/function.chdir



i'd write...

%26lt;?

chdir(%26quot;../%26quot;);

include('index.php');

?%26gt;



one thing many new PHP programers confuse with is that when you include another php file, it still considers the current directory as where it was imported from.



good luck