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?
Lennart EricsonAmateurAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Lennart EricsonConnect With a Mentor AmateurAuthor Commented:
From other sources I have got this answer:
if you're in /meep/bing/  ./foo is /meep/bing/foo, ../foo is /meep/foo, /foo is .. well /foo
0
 
dr_dedoCommented:
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
0
 
Lennart EricsonAmateurAuthor Commented:
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?
0
 
Lennart EricsonAmateurAuthor Commented:
Can anyone explain, please, what's the difference between ../foo.php, ./foo.php and /foo.php?
0
All Courses

From novice to tech pro — start learning today.