Page 1 of 1

How to get the current file name using php

Posted: Mon Jan 18, 2010 2:15 pm
by Neo

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