Current location: Hot Scripts Forums » Programming Languages » PHP » get current file name as variable

get current file name as variable

Reply
  #1 (permalink)  
Old 07-19-03, 02:54 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
get current file name as variable

Hi,

What is the easiest way to get the current file name in the users URL bar as a variable without the domain and sub directories?

Like if they are at http://www.mydomain.com/dir1/dir2/2003_a.php

then

$currentFile = "2003_a.php"

thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-19-03, 04:08 AM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetingz...

PHP Code:
  $currentFile $_SERVER["SCRIPT_NAME"]; 
Hope that helps...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-19-03, 06:52 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Hi ChristGuy

This is what I tried out:

PHP Code:
<?
$currentFile 
$_SERVER["SCRIPT_NAME"];
print 
$currentFile;
?>
On one of the servers I use this was the output:
/cgi-bin/php

On the other server it output:
/test/03.php
where "test" was one directory deep from site root.

I can delete the directory info if I need to on the second one but I have no idea how to handle the first output!

Any ideas?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-20-03, 04:09 AM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
You could try using explode...
PHP Code:
  $currentFile $_SERVER["SCRIPT_NAME"];
  
$parts Explode('/'$currentFile);

  print 
$parts[count($parts)]; 
That should work...
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-23-03, 03:39 AM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, Let me try to be a little more clear. I am looking for a script that will output only "03.php".

The first url was "http://www.domain1.com/test/03.php"
Output was simply "/cgi-bin/php"

The second url was "http://ww.domain2.com/test/03.php"
Output was "/test/03.php"

How should the script be to output only "03.php" -- on both servers?

Thanks ChristGuy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-23-03, 07:58 AM
ChristGuy ChristGuy is offline
Operations Support Develo
 
Join Date: Jun 2003
Location: Rivonia, South Africa
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Greetinz...

If you use the second script what are the results??

And if you use it in a different file on server 1 what do you get?
__________________
Till We Meet Again...
Clifford W. Hansen
Aspivia (Pty) Ltd

"We Have Seen Strange Things Today!" Luke 5:26
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 07-23-03, 04:01 PM
kevin kevin is offline
Newbie Coder
 
Join Date: Jun 2003
Location: USA
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Hi !

Hope this help

Code:
$url ="http://yahoo.com/abcdef/2153abc.gif";

preg_match("/[^\/]+$/",$url,$matches);

$file_name = $matches[0];

print "$file_name";
it will print 2153abc.gif

Regard
Kevin

Last edited by kevin; 07-23-03 at 04:03 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 07-23-03, 05:19 PM
paulj000 paulj000 is offline
Bull in a china shop
 
Join Date: Jul 2003
Location: California, USA
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Hi ChirstGuy,

The output on both servers was nothing. The page was blank when I used the following code only:

PHP Code:
<?
$currentFile 
$_SERVER["SCRIPT_NAME"];
  
$parts Explode('/'$currentFile);

  print 
$parts[count($parts)];
?>
----------------

Hi Kevin,

I need to be able to have the script get the current file name without supplying the url. The script has to determine what the URL is on it's own and then break it down and output the current page/file name.

Thanks guys
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 07-23-03, 05:57 PM
amailer's Avatar
amailer amailer is offline
_-*^# PHP Master #^*-_
 
Join Date: Jun 2003
Location: Canada
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:
<?

$currentFile 
$_SERVER["SCRIPT_NAME"];

$img array_pop(explode("/"$currentFile));

echo 
$img;

?>
see if that works :/
__________________
Amailer - Spam/Advertise/Have fun
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 07-23-03, 07:28 PM
Man Down Man Down is offline
HS Staff
 
Join Date: Jun 2003
Location: Maryland
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Christ Guys code will work if you change it to:

PHP Code:
<?
$currentFile 
$_SERVER["SCRIPT_NAME"];
  
$parts Explode('/'$currentFile);

  print 
$parts[count($parts) - 1];
?>
__________________
Man Down
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New Web Host, New Problem! justchat PHP 2 09-29-03 02:39 PM
Writes to a text file gamextremer2003 JavaScript 4 09-11-03 09:43 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 07:06 PM
how to get info from TXT file between %%customTags%% as vars?? paulj000 PHP 2 07-26-03 05:00 AM
ASP Renaming a file (with some filename parsing) camt ASP 2 06-30-03 09:53 PM


All times are GMT -5. The time now is 03:58 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.