Connecting Tech Pros Worldwide Help | Site Map

Determining Directory of Script

Hugh Cowan
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Guest
 
Posts: n/a
#2: Jul 17 '05

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
Randell D.
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Determining Directory of Script



"Hugh Cowan" <hwcowan@hotmail.com> wrote in message
news:46ca81a0.0310141237.50b5ae8c@posting.google.c om...[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_ENVIRONMENT) and
phpinfo(INFO_VARIABLES).... I always find them useful, especially with forms
processing...


Alan Little
Guest
 
Posts: n/a
#4: Jul 17 '05

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
http://www.phorm.com/
Hugh Cowan
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Determining Directory of Script


André Nęss <andrena.spamreallysucks@ifi.uio.no> wrote in message news:<bmhrs8$85s$1@maud.ifi.uio.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
Closed Thread