How to get the current file name using php

How to get the current file name using php

Postby Neo » Mon Jan 18, 2010 8:45 am

Code: Select all

<?php 
$path 
= $_SERVER["SCRIPT_NAME"];
$file = basename($path);        // $file is set to "myfile.php" 
$file = basename($path, ".php"); // $file is set to "myfile" 
?>


Also, you could use the following method.

Code: Select all

<? 
$currentFile 
= $_SERVER["SCRIPT_NAME"]; 
  $parts 
= Explode('/', $currentFile);
  $parts = array_reverse($parts); 
  echo
("Script is " . $parts[0]);
?>
User avatar
Neo
Site Admin
Site Admin
 
Posts: 2574
Joined: Tue Jul 14, 2009 8:37 pm
Cash on hand: 219,284.90
Bank: 15,536,454.00
Location: Colombo/London
Medals: 2
EC_Bronze_Star (1) EC_Achievment (1)

Invitations sent: 94
Registered friends: 12
Highscores: 13
Reputation point: 71
Lieutenant

Return to PHP & MySQL

Who is online

Users browsing this forum: No registered users and 1 guest