This is a discussion on require_once() ... gone mad? ! within the PHP Language forums, part of the PHP Programming Forums category; I have been struggling with this all afternoon and I'm, well lats just say, very pissed off ... I have ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have been struggling with this all afternoon and I'm, well lats just
say, very pissed off ... I have a require once in a file. I am passing the fully qualified (i.e. absolute pathname) to a file that exists on my machine (I'm looking ath the file now). I am evaluating the pathname like this (see below) Contents of app_config.php =========================== <?php function fix_trailing_char($pathname){ $fixedname = $pathname[strlen($pathname)-1] == "/" ? $pathname : $pathname. "/" ; return $fixedname; } define("DOC_ROOT", fix_trailing_char(dirname($_SERVER["DOCUMENT_ROOT"]))); define("CLASS_ROOT", DOC_ROOT . "classes/"); define("CONFIG_ROOT", DOC_ROOT . "global/"); ?> The file below causes errors ============================== <?php require_once($_SERVER['DOCUMENT_ROOT'] . "global/app_config.php"); require_once(CLASS_ROOT. "common/somefile.php"); ?> I get this error: Warning: require_once(C:/workdir/src/website/classes/common/package.exceptions.errors.php) [function.require-once]: failed to open stream: No such file or directory in C:\workdir\src\website\www\classes\auth\MyControll er.php on line 11 Fatal error: require_once() [function.require]: Failed opening required 'C:/workdir/src/website/classes/common/package.exceptions.errors.php' (include_path='.;C:\workdir\src\website\www\;C:\wo rkdir\src\website\www\classes;C:\workdir\src\websi te\www\classes\mystuff') in C:\workdir\src\website\www\classes\auth\MyControll er.php on line 11 For the cynics out there who may think the file does not exist: C:\workdir\src\website\www\classes\common>dir pack* Volume in drive C has no label. Volume Serial Number is 7C79-29A1 Directory of C:\workdir\src\website\www\classes\common 12/05/2008 15:59 5,885 package.exceptions.errors.php 12/05/2008 16:02 364 package.exceptions.errors.test.php 2 File(s) 6,249 bytes 0 Dir(s) 6,603,599,872 bytes free Incidentally, is there any way for me to change the include_path in a script ? Looking for some answers quickly before I throw my computer out of the window (or better still go back to C++ where everything seems to make so much more sense) |
|
|||
|
Ronald Raygun wrote:
<snip> made typo whilst editing the text to post in the ng. This should read The file below causes errors ============================== <?php require_once($_SERVER['DOCUMENT_ROOT'] . "global/app_config.php"); require_once(CLASS_ROOT. "common/package.exceptions.errors.php"); ?> </snip> |
|
|||
|
On Mon, 12 May 2008 21:22:16 +0200, Ronald Raygun <invalid@domain.com>
wrote: > I have been struggling with this all afternoon and I'm, well lats just > say, very pissed off ... > > I have a require once in a file. I am passing the fully qualified (i.e. > absolute pathname) to a file that exists on my machine (I'm looking ath > the file now). > > I am evaluating the pathname like this (see below) > C:/workdir/src/website/classes/common/package.exceptions.errors.php > C:\workdir\src\website\www\classes\auth\MyControll er.php on -------------------------^^^ I suspect you're missing the 'www' part in the absolute path. Also, aboid absolute paths is possible. Relative to the DOCUMENT_ROOT is easiest & portable, if for a stand alone module this can not be done relative to the file doing the including. > C:\workdir\src\website\www\classes\common>dir pack* That's not the directory you fed it.... > Incidentally, is there any way for me to change the include_path in a > script ? ini_set('include_path','.;C:/etc/;D:/etc/'); > Looking for some answers quickly before I throw my computer out of the > window (or better still go back to C++ where everything seems to make so > much more sense) No matter the language, I don't think any of them has automatic & psychic correcting of wrong paths :P. Keep sane, drink a cup of coffe away from your computer :). -- Rik Wasmus [SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM] |
|
|||
|
On Mon, 12 May 2008 21:34:20 +0200, Rik Wasmus
<luiheidsgoeroe@hotmail.com> wrote: > Also, aboid absolute paths is possible. Relative to the DOCUMENT_ROOT is > easiest & portable, if for a stand alone module this can not be done > relative to the file doing the including. Mea culpa, you allready do that, I was just looking at the error output. Disregard that remark. -- Rik Wasmus [SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM] |
|
|||
|
Ronald Raygun wrote:
> I have been struggling with this all afternoon and I'm, well lats just > say, very pissed off ... > > I have a require once in a file. I am passing the fully qualified (i.e. > absolute pathname) to a file that exists on my machine (I'm looking ath > the file now). > > I am evaluating the pathname like this (see below) > > Contents of app_config.php > =========================== > <?php > function fix_trailing_char($pathname){ > $fixedname = $pathname[strlen($pathname)-1] == "/" ? $pathname : > $pathname. "/" ; > return $fixedname; > } > > define("DOC_ROOT", > fix_trailing_char(dirname($_SERVER["DOCUMENT_ROOT"]))); > define("CLASS_ROOT", DOC_ROOT . "classes/"); > define("CONFIG_ROOT", DOC_ROOT . "global/"); > > ?> > > > > The file below causes errors > ============================== > <?php > require_once($_SERVER['DOCUMENT_ROOT'] . "global/app_config.php"); > require_once(CLASS_ROOT. "common/somefile.php"); > > ?> > > > I get this error: > > Warning: > require_once(C:/workdir/src/website/classes/common/package.exceptions.errors.php) > [function.require-once]: failed to open stream: No such file or > directory in C:\workdir\src\website\www\classes\auth\MyControll er.php on > line 11 > > Fatal error: require_once() [function.require]: Failed opening required > 'C:/workdir/src/website/classes/common/package.exceptions.errors.php' > (include_path='.;C:\workdir\src\website\www\;C:\wo rkdir\src\website\www\classes;C:\workdir\src\websi te\www\classes\mystuff') > in C:\workdir\src\website\www\classes\auth\MyControll er.php on line 11 > > For the cynics out there who may think the file does not exist: > > C:\workdir\src\website\www\classes\common>dir pack* > Volume in drive C has no label. > Volume Serial Number is 7C79-29A1 > > Directory of C:\workdir\src\website\www\classes\common > > 12/05/2008 15:59 5,885 package.exceptions.errors.php > 12/05/2008 16:02 364 package.exceptions.errors.test.php > 2 File(s) 6,249 bytes > 0 Dir(s) 6,603,599,872 bytes free > > > Incidentally, is there any way for me to change the include_path in a > script ? > > Looking for some answers quickly before I throw my computer out of the > window (or better still go back to C++ where everything seems to make so > much more sense) > What are the permissions on the file? Does the webserver have access to it? And are you *sure* the file is: C:/workdir/src/website/classes/common/package.exceptions.errors.php I've been thrown off by a minor typo before! -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Ronald Raygun wrote:
> I have been struggling with this all afternoon and I'm, well lats just > say, very pissed off ... > > I have a require once in a file. I am passing the fully qualified (i.e. > absolute pathname) to a file that exists on my machine (I'm looking ath > the file now). > > I am evaluating the pathname like this (see below) > > Contents of app_config.php > =========================== > <?php > function fix_trailing_char($pathname){ > $fixedname = $pathname[strlen($pathname)-1] == "/" ? $pathname : > $pathname. "/" ; > return $fixedname; > } > > define("DOC_ROOT", > fix_trailing_char(dirname($_SERVER["DOCUMENT_ROOT"]))); > define("CLASS_ROOT", DOC_ROOT . "classes/"); > define("CONFIG_ROOT", DOC_ROOT . "global/"); > > ?> > > > > The file below causes errors > ============================== > <?php > require_once($_SERVER['DOCUMENT_ROOT'] . "global/app_config.php"); > require_once(CLASS_ROOT. "common/somefile.php"); > > ?> > > > I get this error: > > Warning: > require_once(C:/workdir/src/website/classes/common/package.exceptions.errors.php) > [function.require-once]: failed to open stream: No such file or > directory in C:\workdir\src\website\www\classes\auth\MyControll er.php on > line 11 > > Fatal error: require_once() [function.require]: Failed opening required > 'C:/workdir/src/website/classes/common/package.exceptions.errors.php' > (include_path='.;C:\workdir\src\website\www\;C:\wo rkdir\src\website\www\classes;C:\workdir\src\websi te\www\classes\mystuff') > in C:\workdir\src\website\www\classes\auth\MyControll er.php on line 11 > > For the cynics out there who may think the file does not exist: > > C:\workdir\src\website\www\classes\common>dir pack* > Volume in drive C has no label. > Volume Serial Number is 7C79-29A1 > > Directory of C:\workdir\src\website\www\classes\common > > 12/05/2008 15:59 5,885 package.exceptions.errors.php > 12/05/2008 16:02 364 package.exceptions.errors.test.php > 2 File(s) 6,249 bytes > 0 Dir(s) 6,603,599,872 bytes free > > > Incidentally, is there any way for me to change the include_path in a > script ? > > Looking for some answers quickly before I throw my computer out of the > window (or better still go back to C++ where everything seems to make so > much more sense) > Also - these aren't the statements which are including C:/workdir/src/website/classes/common/package.exceptions.errors.php. That line is on line 11 of C:\workdir\src\website\www\classes\auth\MyControll er.php. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Ronald Raygun <invalid@domain.com> wrote:
>... >Contents of app_config.php >=========================== ><?php >function fix_trailing_char($pathname){ > $fixedname = $pathname[strlen($pathname)-1] == "/" ? $pathname : >$pathname. "/" ; > return $fixedname; >} > >define("DOC_ROOT", fix_trailing_char(dirname($_SERVER["DOCUMENT_ROOT"]))); >define("CLASS_ROOT", DOC_ROOT . "classes/"); >define("CONFIG_ROOT", DOC_ROOT . "global/"); > >?> Does PHP on Windows guarantee that $_SERVER["DOCUMENT_ROOT"] uses forward slashes and not backslashes? I didn't realize that. My extensive empirical tests (i.e., 1 system) shows that it seems to be true, but is that in the documentation? -- Tim Roberts, timr@probo.com Providenza & Boekelheide, Inc. |
|
|||
|
Tim Roberts wrote:
> Ronald Raygun <invalid@domain.com> wrote: >> ... >> Contents of app_config.php >> =========================== >> <?php >> function fix_trailing_char($pathname){ >> $fixedname = $pathname[strlen($pathname)-1] == "/" ? $pathname : >> $pathname. "/" ; >> return $fixedname; >> } >> >> define("DOC_ROOT", fix_trailing_char(dirname($_SERVER["DOCUMENT_ROOT"]))); >> define("CLASS_ROOT", DOC_ROOT . "classes/"); >> define("CONFIG_ROOT", DOC_ROOT . "global/"); >> >> ?> > > Does PHP on Windows guarantee that $_SERVER["DOCUMENT_ROOT"] uses forward > slashes and not backslashes? I didn't realize that. My extensive > empirical tests (i.e., 1 system) shows that it seems to be true, but is > that in the documentation? AFAIK, it is always the case, but I see no guarantee. Mixing it up in PHP ('C:\path\sub\adh/asd/asd/asd') is no problem though, and the escaping problem (double your \'s) has allready been passed, the string is OK. -- Rik Wasmus [SPAM] Now looking for some smaller projects to work on to fund a bigger one with delayed pay. If interested, mail rik at rwasmus.nl [/SPAM] |
![]() |
| Thread Tools | |
| Display Modes | |
|
|