Link to home
Start Free TrialLog in
Avatar of Lennart Ericson
Lennart EricsonFlag for Sweden

asked on

how to address a file

First: If one addresses a file , say for inclusion in php like e g include "../foo.php";, the server sees this as going one level towards the server root and then find the file, if it is there.
Secon, my question: Is there a more general way to address the file in question (for inclusion or whatever). Say I want a file to be included in serveral pages throughout the website, and these pages may be found in several folders, at different levels away from the server root. That is also to say could I make a general statement instead of ../foo.php or ../../foo.php or ../../../foo.php when calling that file?
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

you could have a file with list of all files you wish to include and include that file in all other files.
you can use files' absolute path.
e.g.
file include.php
<?php
require_once ("home/usr/etc/xxx/sss/zzz/file.php");
require_once ("home/usr/etc/xxx/ddd/aaa/file5.php");
?>

in any page include file include.php

but, having your include files scattered this way, means that there is a problem with design, and that problem sooner or later will boom your site. do you r best to gather all your include files in one place
Avatar of Lennart Ericson

ASKER

dr_dedo, thanks.

"but, having your include files scattered this way, means that there is a problem with design, and that problem sooner or later will boom your site. do you r best to gather all your include files in one place"

Nevertheless, this is the case. The question was is there a more general way to write the code so one doesn't need to do ../../ etc?
Can anyone explain, please, what's the difference between ../foo.php, ./foo.php and /foo.php?
ASKER CERTIFIED SOLUTION
Avatar of Lennart Ericson
Lennart Ericson
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial