By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,643 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,643 IT Pros & Developers. It's quick & easy.

CLI - Directory path from $_SERVER

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <jo*****@hotmail.com> wrote in message
news:3f******@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

Jul 17 '05 #2

P: n/a
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" <de**@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" <jo*****@hotmail.com> wrote in message
news:3f******@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


Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.