I’m a bit of a PHP newbie, but I’m trying to put some include files in a folder for tidiness. I’ve already been completely stumped by the whole root directory thing (I’ve tried $_SERVER['DOCUMENT_ROOT'] and couldn’t get that to work), but I’m confused why include("../includes/sidebar.php"); doesn’t work either. I can do ../sidebar.php so going up a directory works, but going up and then in another directory doesn’t.
No idea why, I’ve searched lots of forums and couldn’t find any answers…
By the way, it’s on a Linux server (streamline.net) – don’t know anything other than that!
EDIT: Sorry I should’ve posted some server responses. If I try <?php include("../includes/sidebar.php"); ?> get this error:
Warning: include(../includes/sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/fhlinux162/u/___.org.uk/user/htdocs/ufradio/test.php on line 1
Warning: include(../includes/sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/fhlinux162/u/___.org.uk/user/htdocs/ufradio/test.php on line 1
Warning: include() [function.include]: Failed opening '../includes/sidebar.php' for inclusion (include_path='.:/usr/share/pear-php5') in /home/fhlinux162/u/___.org.uk/user/htdocs/ufradio/test.php on line 1
… even if the file exists.
What happens when you try to load the page? Do you get an error message? A blank page? Something else? What is the directory structure and what are the file names? Those would help us write an example for you.
When you are includes files (or otherwise traversing directories), the “..” means “up a level”.
If we are running index.php, and you want to include other.php, just do:
include(‘other.php’);
If you wanted a file inside Subdirectory1, you would use:
include(‘Subdirectory1/some_file.php’);
If you were in Subdirectory1/some_file.php and you wanted to include other.php, you would go up a directory like:
include(“../other.php”);
And if you were in Subdirectory1/some_file.php and you wanted to include yet_another_file.php from Subdirectory2, you would:
include(“../Subdirectory2/yet_another_file.php”);
Hope this helps.