RE: [PHP] include("../file.inc");

From: Date: Tue, 15 May 2001 02:19:37 +0000
Subject: RE: [PHP] include("../file.inc");
Groups: php.general 
Request: Send a blank email to php-general+get-52794@lists.php.net to get a copy of this message
Hi, I came across this problem before, when I was working with windows. Not sure if the same problem occurs in Linux, i guess not as otherwise there would have been tonnes of postings on that then. Well, basically my script architecture spans over at least 3 directory levels. Just for the sake of discussion let my highest directory be A. followed by B, and then C. My A script is the module controller. the B script is the module, and it imports all of its functions by importing scripts contained in C. So my A script has the line : include("B/fileB.php"); My B "fileB.php" script has : include("C/fileC.php"); Theorectically this is sufficient for A to manage my C scripts. However, i realised that PHP wasn't able to do that. The reason being that when A script is runned, the contents of fileB.php are sort of "pasted" onto the A script. Now the A script sort of has a include("C/fileC.php"); line of code. this will generate an error, as there is no C directory relative to the A directory. 1. you may have generated errors if you have, like me, been working with multiple directories, and not taken notice of that subtle problem above. The work-around is to put include("B/C/fileC.php"); in the B script. 2. in your case "require" or "include" makes no difference, but there is a subtle difference when used in other situations, you might wanna check that out when you are free. 3. My example above is slightly different from yours as yours is traversing up a tree, mine was traversing down the tree. However, the conclusion still stands: take note and display full paths when working with directory levels exceeding 2. If theres anything you'll like to ask about what i said here, or otherwise, pl mail me directly, as i dun check this list very often. All the best then! =) kelvin Chan Message-ID: <2B25A9C95DC8D411BBE500508BB19239515CF8@ntslxch1.int.rdel.co.uk> From: "Taylor, Stewart" <Stewart.Taylor@uk.thalesgroup.com> To: "'Matthew Ralston'" <matthew.ralston@haltoncollege.ac.uk>, php-general@lists.php.net Date: Fri, 11 May 2001 11:52:17 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Subject: RE: [PHP] include("../file.inc"); Either of the first two should work under linux. I have done similar many times myself e.g. require_once "../common/localvars.php"; -Stewart -----Original Message----- From: Matthew Ralston [mailto:matthew.ralston@haltoncollege.ac.uk] Sent: 11 May 2001 11:40 To: php-general@lists.php.net Subject: [PHP] include("../file.inc"); How do you include or require a file that is above the current script in the directory hierarchy? For example how would I include or require a file whose path is "../file.inc" relative to the current script? I tried all of: include("../file.inc"); require("../file.inc"); include("/file.inc"); require("/file.inc"); include("..\file.inc"); require("..\file.inc"); include("\file.inc"); require("\file.inc"); but it doen't like any of them. :( I don't want to use a full path relative to the root of the drive or webserver folder because the included file and the script may move as the development server is setup differently to the real web server. Any ideas? -- Thanks, Matt matthew.ralston@haltoncollege.ac.uk < www.mralston.co.uk /> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net _________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

« previous php.general (#52794) next »