PHP For Beginners

Code samples and code snippets for new php programmers

PHP For Beginners header image 2

PHP Absolute Path

November 5th, 2008 by Esa

For MYSQL and many other applications, it’s necessary sometimes to figure out the absolute path to a certain file.

Here’s how to find absolute path using a simple PHP script:

$path = getcwd();
echo “Your Absolute Path is: “;
echo $path;

Just create the file ‘absolute.php’ in the directory that you wish to find the absolute path for, and copy-paste the above code to the file, save it and run it.

Tags: 2 Comments

Leave A Comment

2 responses so far ↓

  • 1 Dicky Kurniawan Nov 6, 2008 at 5:38 am

    Or you can use this $path = __FILE__ ; to get current absolute file path. Btw nice one, i did not know getcwd() before :)

  • 2 Esa Nov 7, 2008 at 10:34 am

    Thanks, I didn’t know about __FILE__ either