CLI - Directory path from $_SERVER

This is a discussion on CLI - Directory path from $_SERVER within the PHP Language forums, part of the PHP Programming Forums category; I need the path of the script that is running. Unfortunately it is not in the $_SERVER array when running ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-05-2003
chops
 
Posts: n/a
Default CLI - Directory path from $_SERVER

I need the path of the script that is running. Unfortunately it is not in
the $_SERVER array when running a script through the CLI.

Through a browser I can strip the script name off, e.g
$_SERVER['SCRIPT_FILENAME'] => "C:/Apache2/htdocs/test/filename.php"

However through the CLI the path doesn't appear in
$_SERVER['SCRIPT_FILENAME']. Only the script name.

Actually $_SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'] and
$_SERVER['PATH_TRANSLATED'] all contain the same thing.. the name of the
scipt only.

I know that it's possible to execute external commands through the CLI, but
thats not portable.

I considered writing this up as a bug. But I thought I'd ask here first.
Maybe theres a setting in php.ini I'm missing.

btw I tested this on php 5.0 and 4.3.

Thanks,
Joel


Reply With Quote
  #2 (permalink)  
Old 11-05-2003
ChronoFish
 
Posts: n/a
Default Re: CLI - Directory path from $_SERVER

Hi Joel,

Don't know if this helps, but it my PHP CGI/CLI I have been using the
following:

// Set the document root
if ($_SERVER['DOCUMENT_ROOT'] == "") $_SERVER['DOCUMENT_ROOT'] =
getcwd()."/../";


getcwd() is portable and alway reports the location of the script being
executed - in my case it's alway in the cgi-bin directory. I cheat here by
assuming that the CGI-BIN directory is contained in the htdocs directory.
The way I will be getting around this is by saving user settings to an ini
file.


- CF



"chops" <joel700@hotmail.com> wrote in message
news:3fa8567d@news.comindico.com.au...
> I need the path of the script that is running. Unfortunately it is not in
> the $_SERVER array when running a script through the CLI.
>
> Through a browser I can strip the script name off, e.g
> $_SERVER['SCRIPT_FILENAME'] => "C:/Apache2/htdocs/test/filename.php"
>
> However through the CLI the path doesn't appear in
> $_SERVER['SCRIPT_FILENAME']. Only the script name.
>
> Actually $_SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'] and
> $_SERVER['PATH_TRANSLATED'] all contain the same thing.. the name of the
> scipt only.
>
> I know that it's possible to execute external commands through the CLI,

but
> thats not portable.
>
> I considered writing this up as a bug. But I thought I'd ask here first.
> Maybe theres a setting in php.ini I'm missing.
>
> btw I tested this on php 5.0 and 4.3.
>
> Thanks,
> Joel
>
>



Reply With Quote
  #3 (permalink)  
Old 11-05-2003
chops
 
Posts: n/a
Default Re: CLI - Directory path from $_SERVER

Oops, I missed that function in the manual :P
Thanks CF.

I'd still like to know why those 3 $_SERVER vars are all the same in the
CLI.


"ChronoFish" <deja@chronofish.com> wrote in message
news:L8_pb.1570$oB3.511@lakeread03...
> Hi Joel,
>
> Don't know if this helps, but it my PHP CGI/CLI I have been using the
> following:
>
> // Set the document root
> if ($_SERVER['DOCUMENT_ROOT'] == "") $_SERVER['DOCUMENT_ROOT'] =
> getcwd()."/../";
>
>
> getcwd() is portable and alway reports the location of the script being
> executed - in my case it's alway in the cgi-bin directory. I cheat here

by
> assuming that the CGI-BIN directory is contained in the htdocs directory.
> The way I will be getting around this is by saving user settings to an ini
> file.
>
>
> - CF
>
>
>
> "chops" <joel700@hotmail.com> wrote in message
> news:3fa8567d@news.comindico.com.au...
> > I need the path of the script that is running. Unfortunately it is not

in
> > the $_SERVER array when running a script through the CLI.
> >
> > Through a browser I can strip the script name off, e.g
> > $_SERVER['SCRIPT_FILENAME'] => "C:/Apache2/htdocs/test/filename.php"
> >
> > However through the CLI the path doesn't appear in
> > $_SERVER['SCRIPT_FILENAME']. Only the script name.
> >
> > Actually $_SERVER['SCRIPT_NAME'], $_SERVER['SCRIPT_FILENAME'] and
> > $_SERVER['PATH_TRANSLATED'] all contain the same thing.. the name of the
> > scipt only.
> >
> > I know that it's possible to execute external commands through the CLI,

> but
> > thats not portable.
> >
> > I considered writing this up as a bug. But I thought I'd ask here first.
> > Maybe theres a setting in php.ini I'm missing.
> >
> > btw I tested this on php 5.0 and 4.3.
> >
> > Thanks,
> > Joel
> >
> >

>
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 07:03 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0