Re: [PHP] Get filename in php command line

2001-07-17 Thread Jason Bell

$PHP_SELF returns the filename with the full path. from there, you can use
split to split the string wherever a / occurs, then call count, to get the
total number of values in the array, decrememnt the count by 1 (Arrays begin
at 0) then, set a variable to store just the filename, like so:

$fullpath = split('/',$PHP_SELF);
$c = count($fullpath);
$c--;
$filename = $fullpath[$c];

There may be a better way to do it, but this works for me, and it's only 4
lines. :)

JB


- Original Message -
From: Reuben D Budiardja [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, July 17, 2001 7:48 AM
Subject: [PHP] Get filename in php command line



Hello,
How do I get the filename or script name if I run it in php comamnd line?
For
example, if I run this

bash$ php test.php

I want to get something inside test.php that tells me the filename is
test.php, but *without* the actual path.

Thanks
Reuben D. Budiardja

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Get filename in php command line

2001-07-17 Thread Reuben D Budiardja

Seems that $PHP_SELF is not defined when it's run from the command line.

Reuben D. Budiardja

On Tuesday 17 July 2001 10:29 am, Jason Bell wrote:
 $PHP_SELF returns the filename with the full path. from there, you can use
 split to split the string wherever a / occurs, then call count, to get the
 total number of values in the array, decrememnt the count by 1 (Arrays
 begin at 0) then, set a variable to store just the filename, like so:

 $fullpath = split('/',$PHP_SELF);
 $c = count($fullpath);
 $c--;
 $filename = $fullpath[$c];

 There may be a better way to do it, but this works for me, and it's only 4
 lines. :)

 JB


 - Original Message -
 From: Reuben D Budiardja [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Tuesday, July 17, 2001 7:48 AM
 Subject: [PHP] Get filename in php command line



 Hello,
 How do I get the filename or script name if I run it in php comamnd line?
 For
 example, if I run this

 bash$ php test.php

 I want to get something inside test.php that tells me the filename is
 test.php, but *without* the actual path.

 Thanks
 Reuben D. Budiardja


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Get filename in php command line

2001-07-17 Thread Boget, Chris

 Seems that $PHP_SELF is not defined when it's run from the 
 command line.

Try:

__FILE__

Chris



Re: [PHP] Get filename in php command line

2001-07-17 Thread Reuben D Budiardja

I had that before. 
OK, seems that my problem is not that simple. The thing is , I have something 
like this in my file test.php:

require('my_api.inc');
echo This is test.php3;

Now, in my_api.inc, I want to know that I run test.php3, when I do
bash$ php test.php3

and the filename is test.php3 .  __FILE__ will give my my_api.inc instead.  I 
need it because my_api.inc do all sort of authenticating, session, etc.

Any solutions?
Thanks.
Reuben D. Budiardja


On Tuesday 17 July 2001 10:52 am, Boget, Chris wrote:
  Seems that $PHP_SELF is not defined when it's run from the
  command line.

 Try:

 __FILE__

 Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Get filename in php command line

2001-07-17 Thread Boget, Chris

 I had that before. 
 OK, seems that my problem is not that simple. The thing is , 
 I have something 
 like this in my file test.php:
 require('my_api.inc');
 echo This is test.php3;
 Now, in my_api.inc, I want to know that I run test.php3, when I do
 bash$ php test.php3
 and the filename is test.php3 .  __FILE__ will give my my_api.inc 
 instead.  I need it because my_api.inc do all sort of authenticating, 
 session, etc.

__FILE__ will give you the name of the file that uses that constant.
So, based on the above, I believe that you are using __FILE__ only
in my_api.inc (which is pretty much what you said, I'm just looking
for verification).

What you can do instead is this:

in my_api.inc, have the following code:

echo Currently Running file is: ;
echo ( $CurrentRunningFile ) ? $CurrentRunningFile : __FILE__;

in test.php

?
  $CurrentRunningFile = __FILE__;

  include( my_api.inc );
  echo This is test.php3br\n;
?

Define $CurrentRunningFile on line one of all your files.  Or
something along those lines...

Chris



Re: [PHP] Get filename in php command line

2001-07-17 Thread Reuben D Budiardja

On Tuesday 17 July 2001 11:14 am, Boget, Chris wrote:
 in my_api.inc, have the following code:

 echo Currently Running file is: ;
 echo ( $CurrentRunningFile ) ? $CurrentRunningFile : __FILE__;

 in test.php

 ?
   $CurrentRunningFile = __FILE__;

   include( my_api.inc );
   echo This is test.php3br\n;
 ?

 Define $CurrentRunningFile on line one of all your files.  Or
 something along those lines...

 Chris

Well, I thought about that too. The thing is, this is part of the bigger 
project to make our apps can be run from command line, and we already have 
tons of apps that currently running from web. Doing that for every single 
apps would be a pain. But apparently since there is no other way, at least at 
this point, it will have do for some apps.

Thanks.
Reuben D. Budiardja

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]