1

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...

Community
  • 1
  • 1
fwho
  • 248
  • 2
  • 14

3 Answers3

2

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

jamis0n
  • 3,610
  • 8
  • 34
  • 50
2

../ 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.

Shauna
  • 9,495
  • 2
  • 37
  • 54
0

../ 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');
OakNinja
  • 2,326
  • 18
  • 20