Determining Directory of Script

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hugh Cowan

    Determining Directory of Script

    Hello,

    I am currently running PHP 4.3.2 on Windows NT 4.0.

    Is there anyway (I am sure there is but I just can't find it) that you
    can determine the path of the current script that is running?

    I have created a command line script that processes some files and I
    would like to be able to drop the script in a given directory and then
    run it from there.

    In this manner the "active directory" will change depending upon where
    I call the script from. Rather than having to change the script each
    time, or having to hard-code a directory in-place, I would rather keep
    it dynamic if possible.

    Thanks,

    Hugh
  • André Næss

    #2
    Re: Determining Directory of Script

    Hugh Cowan:
    [color=blue]
    > I am currently running PHP 4.3.2 on Windows NT 4.0.
    >
    > Is there anyway (I am sure there is but I just can't find it) that you
    > can determine the path of the current script that is running?[/color]

    $cwd = dirname(__FILE_ _);

    This works across platforms.

    André Næss

    Comment

    • Randell D.

      #3
      Re: Determining Directory of Script


      "Hugh Cowan" <hwcowan@hotmai l.com> wrote in message
      news:46ca81a0.0 310141237.50b5a e8c@posting.goo gle.com...[color=blue]
      > Hello,
      >
      > I am currently running PHP 4.3.2 on Windows NT 4.0.
      >
      > Is there anyway (I am sure there is but I just can't find it) that you
      > can determine the path of the current script that is running?
      >
      > I have created a command line script that processes some files and I
      > would like to be able to drop the script in a given directory and then
      > run it from there.
      >
      > In this manner the "active directory" will change depending upon where
      > I call the script from. Rather than having to change the script each
      > time, or having to hard-code a directory in-place, I would rather keep
      > it dynamic if possible.
      >
      > Thanks,
      >
      > Hugh[/color]

      Yep - view the output from phpinfo(); and it should help... There are
      methods to get the path of your running script in addition to the path of
      any file that was included, if it sat in a different folder... Always keep
      phpinfo in mind (check its syntax as some of the info you won't need and you
      can cut it down a bit with something like phpinfo(INFO_EN VIRONMENT) and
      phpinfo(INFO_VA RIABLES).... I always find them useful, especially with forms
      processing...


      Comment

      • Alan Little

        #4
        Re: Determining Directory of Script

        Carved in mystic runes upon the very living rock, the last words of Hugh
        Cowan of comp.lang.php make plain:
        [color=blue]
        > Is there anyway (I am sure there is but I just can't find it) that you
        > can determine the path of the current script that is running?[/color]

        It sounds like you'll be using it in a consistent environment, so the
        previous suggestions should serve you well, but if not there's always ./

        This was something I went round and round with in Phorm, which has to run
        on all kinds of different platforms with all kinds of different
        configurations; some variables or commands would work in some
        circumstances and not in others. I don't know that there is any 100%
        cross-platform, cross-configuration way to determine the absolute path of
        the script.

        --
        Alan Little
        Phorm PHP Form Processor

        Comment

        • Hugh Cowan

          #5
          Re: Determining Directory of Script

          André Næss <andrena.spamre allysucks@ifi.u io.no> wrote in message news:<bmhrs8$85 s$1@maud.ifi.ui o.no>...[color=blue]
          > Hugh Cowan:
          >[color=green]
          > > I am currently running PHP 4.3.2 on Windows NT 4.0.
          > >
          > > Is there anyway (I am sure there is but I just can't find it) that you
          > > can determine the path of the current script that is running?[/color]
          >
          > $cwd = dirname(__FILE_ _);
          >
          > This works across platforms.
          >
          > André Næss[/color]

          Thank-you, thank-you, thank-you!!!! Works perfectly -- just what I was
          looking for. Thanks so much for the reply and answer. As other
          people have posted there are some global variables that contain the
          same type of information -- however I cannot seem to get access to
          them.

          When I run the phpinfo() function and look at the results displayed
          there is nothing that shows the current directory, or directory of
          current script. I noticed that if I look in the help manual there are
          suppose to be a variety of variables that do just that, but I couldn't
          find them.

          I don't know if it's because I am running on Windows, or because I am
          running scripts locally and not through a web-server??

          Anyways -- it doesn't matter now, I have my answer and I can stop
          pulling my hair out.

          Thanks again,

          Hugh

          Comment

          Working...