08 November, 2010

Get path of a file in PHP

Once i have to get location of a file using a single line of code in php. Here's how i did it.

$filePath = substr($_SERVER["SCRIPT_FILENAME"], 0, strrpos($_SERVER["SCRIPT_FILENAME"], "/"));
echo $filePath; // this gives the full file path

Hope it helps someone.