Sometimes you need to know the full path or absolute path of a directory or a file stored on a web server. For example if you are using .htaccess file to password protect your WordPress wp-admin directory, you need to specify the absolute path of the .htpasswd file (Apache password file) in the .htacecss file or the authentication does not work.
Below is a simple three line PHP script which you can use to find out the absolute path of the directory where it is uploaded.
<?php echo getcwd(); ?>
Procedure to find the absolute path of a directory on your website
- Launch notepad or any text editor of your choice
- Copy the above script to the new file
- Save the file as path.php
- Using an FTP client, upload path.php to the directory which you want to know the path of
- Using a web browser, navigating to the script e.g. http://www.website.com/directory/path.php