Possible Duplicate:
Relative include files
For example,
include('../admin/db_cred.php');
That works if I am in another folder such as public. However if I am just at www.SITE.com/index.php, it does not work.
Warning: include(../admin/db_cred.php) [function.include]: failed to open stream: No such file or directory in /home/[...].php on line 6
I added the (dot dot slash) because searching ../ does not work very well...
The ../
convention indicates to move up one directory level from where you are. If you are in the root directory, you cannot move up any more levels.
If your /admin folder is in the root directory and you call this from the /public directory, then ../admin/
would allow you to select the /admin folder from one level below
../ is parent folder, but root have no parent.
If you want to resolve
http://site/admin/db_cred.php
you should write it like this:
include('~/admin/db_cred.php');
../
means "the folder above this one" or "move up a folder." For example, if you are in a terminal and enter cd ../
you will move up a folder from where you started.
When you're at site.com/index
, you are very likely in the web root of your site and, therefore, cannot go up a level, because there is no level up.
"But there are folders above /var/www
!" Yes, there are, but your scripts do not have access to them (this is a very good thing, you don't want a hijacked script to gain access to your entire server). As far as your scripts are concerned, /var/www
(or whatever your web root is) is the topmost level, regardless of what is actually on the filesystem.