RE: [PHP] how to get the absolute path of an included file?
| From: | Ford, Mike | Date: | Thu, 27 Apr 2006 15:05:31 +0000 |
| Subject: | RE: [PHP] how to get the absolute path of an included file? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-234933@lists.php.net to get a copy of this message | ||
On 27 April 2006 15:25, Brad Bonkoski wrote:
> Bing Du wrote:
>
> > Hello,
> >
> > Here are the two scripts. The result is 'var is' rather than 'var
> > is foo'. My suspect is I did not set the file path right in
> > 'include'. So in file2.php, how should I get the actual absolute
> > path it really gets for file1.php? Is it stored in some
> > environment variable or something? I'd appreciate any help.
> >
> > file1.php
> >
> > ==
> > <?php
> > $var = 'foo';
> > >
> > ==
> >
> > file2.php
> >
> > ==
> > <?php
> >
> > include '/some/path/file1.php';
> >
> >
> global $var; //you have to declare it as a global otherwise it will
> assume a local value
Complete twaddle. That only applies for functions.
This is likely to be, as Bing deduced, a path error on the include filename.
Bear in mind that include works relative to your file-system's root, not your Web site's
document root -- so is the filename you're using an absolute path in your file-system?
And, whilst we're at it, have you got display_errors=On and error_reporting=E_ALL so that you
see all error reports, including warnings. Odds on this will give you some sort of clue.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@leedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm