Method 1
	To display full path name
	<?php
	echo $_SERVER['PHP_SELF'];
	?>
	Output ==> /public_html/index.php
	Method 2
	To display only the file name use the following query.
	<?php
	    $currentFile = $_SERVER["PHP_SELF"];
	    $parts = Explode('/', $currentFile);
	    echo $parts[count($parts) - 1];
	?>
	Output ==> index.php
	Method 3
	<?php
echo realpath(dirname(__FILE__));
		?>
	
		Output ==> C:\wamp\www\public_html\wp-content\plugins\exec-php\includes
	
Method 4
<?php
echo getcwd();
?>
Output ==> C:\wamp\www\public_html
Method 5
<?php
echo $file=$_SERVER['DOCUMENT_ROOT'];
?>
Output ==> C:/wamp/www/
		Method 6
	
<?php
echo $_SERVER["SCRIPT_FILENAME"];
?>
Output ==> C:/wamp/www/public_html/index.php
No comments:
Post a Comment