How to get the current file name using php

Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

How to get the current file name using php

Post by Neo » Mon Jan 18, 2010 2:15 pm

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]);
?>
Post Reply

Return to “PHP & MySQL”