1

include "con.php" would find the con.php file in the current folder.

include "../con.php" would find it in the folder above.

What is the syntax to find it in the folder 2 above?

and lastly, what is the syntax to find it in the folder which is in the same "above one" folder? (like if i have a folder MAIN, with foldersONE and TWO in it. con.php is in TWO and the file to be run is in ONE)?

Thanks!

2
  • 1
    do not address files this way. Always use absolute path Commented Jan 24, 2011 at 15:07
  • Have to agree with @Col. Shrapnel. See my answer for an example of how to do this. Commented Jan 24, 2011 at 16:40

3 Answers 3

2

../../con.php

This would get you 2 levels up.

../TWO/con.php

Would take you one level up, and then down into TWO where con.php is.

Sign up to request clarification or add additional context in comments.

Comments

1

It's ../ for each folder, so ../../ for two folder.

Comments

1

Whilst not entirely on-topic, I'd recommend creating a define for your "base" HTML directory and accessing all includes, images, etc. relative to that. (If you have a specific "includes" directory, you could of course create a specific define for that as well.)

For example:

define('__BASEPATH', str_replace('//', '/', $_SERVER['DOCUMENT_ROOT'].'/'), true);
include __BASEPATH.'includes/con.php';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.