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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 > > |
|
|||
|
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 > > > > > > |