PHP/File Directory/dirname
dirname.php
<?php
$path = "/home/www/data/users.txt";
$dirname = dirname($path); // $dirname contains "/home/www/data"
?>
Use dirname() with predefined variable $SCRIPT_FILENAME to obtain the complete path of the script executing the command
<?
$dir = dirname($SCRIPT_FILENAME);
print $dir;
?>