Page 1 of 1

Query: Can you 'include' a file that is up a level?

Posted: Wed Mar 31, 2004 4:04 pm
by randomblink
For isntance...

Here is my directory:
[root folder]
+ data.php
+ user.php
+[FolderX]
++ index.php
++[FolderY]
+++test.php

How would I INCLUDE the data.php which is TWO LEVELS HIGHER?
I tried doing something like:
include("../../data.php");

But it wouldn't reach it...
Can someone help? Thanks...

Posted: Wed Mar 31, 2004 4:09 pm
by markl999
Just set the include_path in php.ini, a vhost section of httpd.conf or using ini_set() to /path/to/rootfolder then you can require/include 'data.php' in any file regardless of which directory it's in.

Posted: Wed Mar 31, 2004 4:14 pm
by randomblink
Wha?

Forgive the eloquence of my reply... but Wha?!

These are all new to me...
I do know that I can't access alot of php settings cause those are handled by my webhost... Can I set this through straight php in a php file?

Posted: Wed Mar 31, 2004 4:18 pm
by markl999
Well as you're on a webhost, try this. In a file called .htaccess put:

php_value include_path /the/full/path/to/the/root/folder

Put the .htaccess directory in the root folder. This should allow you to require/include data.php in any file, from anywhere. The include_path sets the path to be searched when you use include or require.

Posted: Wed Mar 31, 2004 4:24 pm
by randomblink
Bear with me...

When you say put the /full/path/to/the/root/folder in this .htaccess file, do you mean like this?

/root folder/

Or do you mean the path to the root folder FROM where the include file is?

/../../root folder/

or do you mean FROM the root folder TO the file that is INCLUDING...

/root folder/FolderX/test.php/

I am sorry to be so basic here, I just am confused...

Posted: Wed Mar 31, 2004 4:41 pm
by pickle
When you tried to

Code: Select all

include('../../data.php');
did it output an error or anything? If it can't reach it, usually the error that is output is something like it cannot find the file or permission denied. Try echoing something from the data.php file so you can see when it is included.

Posted: Wed Mar 31, 2004 4:55 pm
by markl999
When you say put the /full/path/to/the/root/folder in this .htaccess file, do you mean like this?
I mean the full web directory path, eg /home/fred/www/root .. basically whatever echo $_SERVER['DOCUMENT_ROOT'] returns.

Posted: Thu Apr 01, 2004 9:44 am
by randomblink
Ok. I entered the:

php_value include_path /the/full/path/to/the/root/folder

I cut and pasted the above line and copied over the:

/the/full/path/to/the/root/folder

with the output from a:
echo $_SERVER['DOCUMENT_ROOT'];

command... The command was run from a php file IN the root folder... (if that matters) But I ran it, cut and pasted it over the:

/the/full/path/to/the/root/folder

line... SO hopefully this works...!
Thanks for all your help...