require_once() ... gone mad? !

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald Raygun

    require_once() ... gone mad? !

    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_ch ar($pathname){
    $fixedname = $pathname[strlen($pathnam e)-1] == "/" ? $pathname :
    $pathname. "/" ;
    return $fixedname;
    }

    define("DOC_ROO T", fix_trailing_ch ar(dirname($_SE RVER["DOCUMENT_R OOT"])));
    define("CLASS_R OOT", 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(CL ASS_ROOT. "common/somefile.php");

    ?>


    I get this error:

    Warning:
    require_once(C:/workdir/src/website/classes/common/package.excepti ons.errors.php)
    [function.requir e-once]: failed to open stream: No such file or
    directory in C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php on
    line 11

    Fatal error: require_once() [function.requir e]: Failed opening required
    'C:/workdir/src/website/classes/common/package.excepti ons.errors.php'
    (include_path=' .;C:\workdir\sr c\website\www\; C:\workdir\src\ website\www\cla sses;C:\workdir \src\website\ww w\classes\mystu ff')
    in C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php on line 11

    For the cynics out there who may think the file does not exist:

    C:\workdir\src\ website\www\cla sses\common>dir pack*
    Volume in drive C has no label.
    Volume Serial Number is 7C79-29A1

    Directory of C:\workdir\src\ website\www\cla sses\common

    12/05/2008 15:59 5,885 package.excepti ons.errors.php
    12/05/2008 16:02 364 package.excepti ons.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

    #2
    Re: require_once() ... gone mad? !

    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(CL ASS_ROOT. "common/package.excepti ons.errors.php" );

    ?>
    </snip>

    Comment

    • Rik Wasmus

      #3
      Re: require_once() ... gone mad? !

      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.excepti ons.errors.php
      C:\workdir\src\ website\www\cla sses\auth\MyCon troller.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\cla sses\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('includ e_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]

      Comment

      • Rik Wasmus

        #4
        Re: require_once() ... gone mad? !

        On Mon, 12 May 2008 21:34:20 +0200, Rik Wasmus
        <luiheidsgoeroe @hotmail.comwro te:
        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]

        Comment

        • Jerry Stuckle

          #5
          Re: require_once() ... gone mad? !

          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_ch ar($pathname){
          $fixedname = $pathname[strlen($pathnam e)-1] == "/" ? $pathname :
          $pathname. "/" ;
          return $fixedname;
          }
          >
          define("DOC_ROO T",
          fix_trailing_ch ar(dirname($_SE RVER["DOCUMENT_R OOT"])));
          define("CLASS_R OOT", 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(CL ASS_ROOT. "common/somefile.php");
          >
          ?>
          >
          >
          I get this error:
          >
          Warning:
          require_once(C:/workdir/src/website/classes/common/package.excepti ons.errors.php)
          [function.requir e-once]: failed to open stream: No such file or
          directory in C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php on
          line 11
          >
          Fatal error: require_once() [function.requir e]: Failed opening required
          'C:/workdir/src/website/classes/common/package.excepti ons.errors.php'
          (include_path=' .;C:\workdir\sr c\website\www\; C:\workdir\src\ website\www\cla sses;C:\workdir \src\website\ww w\classes\mystu ff')
          in C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php on line 11
          >
          For the cynics out there who may think the file does not exist:
          >
          C:\workdir\src\ website\www\cla sses\common>dir pack*
          Volume in drive C has no label.
          Volume Serial Number is 7C79-29A1
          >
          Directory of C:\workdir\src\ website\www\cla sses\common
          >
          12/05/2008 15:59 5,885 package.excepti ons.errors.php
          12/05/2008 16:02 364 package.excepti ons.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.excepti ons.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@attgl obal.net
          =============== ===

          Comment

          • Jerry Stuckle

            #6
            Re: require_once() ... gone mad? !

            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_ch ar($pathname){
            $fixedname = $pathname[strlen($pathnam e)-1] == "/" ? $pathname :
            $pathname. "/" ;
            return $fixedname;
            }
            >
            define("DOC_ROO T",
            fix_trailing_ch ar(dirname($_SE RVER["DOCUMENT_R OOT"])));
            define("CLASS_R OOT", 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(CL ASS_ROOT. "common/somefile.php");
            >
            ?>
            >
            >
            I get this error:
            >
            Warning:
            require_once(C:/workdir/src/website/classes/common/package.excepti ons.errors.php)
            [function.requir e-once]: failed to open stream: No such file or
            directory in C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php on
            line 11
            >
            Fatal error: require_once() [function.requir e]: Failed opening required
            'C:/workdir/src/website/classes/common/package.excepti ons.errors.php'
            (include_path=' .;C:\workdir\sr c\website\www\; C:\workdir\src\ website\www\cla sses;C:\workdir \src\website\ww w\classes\mystu ff')
            in C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php on line 11
            >
            For the cynics out there who may think the file does not exist:
            >
            C:\workdir\src\ website\www\cla sses\common>dir pack*
            Volume in drive C has no label.
            Volume Serial Number is 7C79-29A1
            >
            Directory of C:\workdir\src\ website\www\cla sses\common
            >
            12/05/2008 15:59 5,885 package.excepti ons.errors.php
            12/05/2008 16:02 364 package.excepti ons.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.excepti ons.errors.php.
            That line is on line 11 of
            C:\workdir\src\ website\www\cla sses\auth\MyCon troller.php.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Tim Roberts

              #7
              Re: require_once() ... gone mad? !

              Ronald Raygun <invalid@domain .comwrote:
              >...
              >Contents of app_config.php
              >============== =============
              ><?php
              >function fix_trailing_ch ar($pathname){
              > $fixedname = $pathname[strlen($pathnam e)-1] == "/" ? $pathname :
              >$pathname. "/" ;
              > return $fixedname;
              >}
              >
              >define("DOC_RO OT", fix_trailing_ch ar(dirname($_SE RVER["DOCUMENT_R OOT"])));
              >define("CLASS_ ROOT", DOC_ROOT . "classes/");
              >define("CONFIG _ROOT", DOC_ROOT . "global/");
              >
              >?>
              Does PHP on Windows guarantee that $_SERVER["DOCUMENT_R OOT"] 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.

              Comment

              • Rik Wasmus

                #8
                Re: require_once() ... gone mad? !

                Tim Roberts wrote:
                Ronald Raygun <invalid@domain .comwrote:
                >...
                >Contents of app_config.php
                >============== =============
                ><?php
                >function fix_trailing_ch ar($pathname){
                > $fixedname = $pathname[strlen($pathnam e)-1] == "/" ? $pathname :
                >$pathname. "/" ;
                > return $fixedname;
                >}
                >>
                >define("DOC_RO OT", fix_trailing_ch ar(dirname($_SE RVER["DOCUMENT_R OOT"])));
                >define("CLASS_ ROOT", DOC_ROOT . "classes/");
                >define("CONFIG _ROOT", DOC_ROOT . "global/");
                >>
                >?>
                >
                Does PHP on Windows guarantee that $_SERVER["DOCUMENT_R OOT"] 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\a dh/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]

                Comment

                Working...