No credit card. Takes under a minute.

Login
INSIGHTS1 MIN READ

How To Find The Full Path To A File Using PhP

workwithyang

Published on September 10, 2015

Published on Wealthy Affiliate — a platform for building real online businesses with modern training and AI.

Recently, I found myself needing to password protect a few folders on my website. I spent many hours reviewing YouTube videos and articles and figured out that I need to have two files: .htaccess and .htpasswd.

The .htaccess file is where I would have information on where the system would go authenticate the username and password that would be entered by the user. .htpasswd is the file that would contain the username and password.

But I kept getting stuck on finding the full path to where I would be placing my .htpasswd file. I probably spent a good 24 hours trying to figure it out, and now I've finally figured it out.

Ready to put this into action?

Start your free journey today — no credit card required.

All you have to do is create the script below. Copy the code and paste it into a file called fullpath.php. You can then upload the file to the directory where you want to place the .htpasswd. Then point your browser to http://www.your-domain.com/path/to/fullpath.php

Here is the script:

<?php
$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";
?>

Share this insight

This conversation is happening inside the community.

Join free to continue it.

The Internet Changed. Now It Is Time to Build Differently.

If this article resonated, the next step is learning how to apply it. Inside Wealthy Affiliate, we break this down into practical steps you can use to build a real online business.

No credit card. Instant access.

2.9M+

Members

190+

Countries Served

20+

Years Online

50K+

Success Stories

The world's most successful affiliate marketing training platform. Join 2.9M+ entrepreneurs building their online business with expert training, tools, and support.

Member Login

© 2005-2026 Wealthy Affiliate
All rights reserved worldwide.

🔒 Trusted by Millions Worldwide

Since 2005, Wealthy Affiliate has been the go-to platform for entrepreneurs looking to build successful online businesses. With industry-leading security, 99.9% uptime, and a proven track record of success, you're in safe hands.