How To Find The Full Path To A File Using PhP
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.
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>";
?>
Join FREE & Launch Your Business!
Exclusive Bonus - Offer Ends at Midnight Today
00
Hours
:
00
Minutes
:
00
Seconds
2,000 AI Credits Worth $10 USD
Build a Logo + Website That Attracts Customers
400 Credits
Discover Hot Niches with AI Market Research
100 Credits
Create SEO Content That Ranks & Converts
800 Credits
Find Affiliate Offers Up to $500/Sale
10 Credits
Access a Community of 2.9M+ Members
Recent Comments
2
Join FREE & Launch Your Business!
Exclusive Bonus - Offer Ends at Midnight Today
00
Hours
:
00
Minutes
:
00
Seconds
2,000 AI Credits Worth $10 USD
Build a Logo + Website That Attracts Customers
400 Credits
Discover Hot Niches with AI Market Research
100 Credits
Create SEO Content That Ranks & Converts
800 Credits
Find Affiliate Offers Up to $500/Sale
10 Credits
Access a Community of 2.9M+ Members
Hi Yang hard core or was it hard out to get an outcome .
Alexander
Don't fully understand your question but it took me a while to figure out what I need to do to find out the full path to a folder on my website. But now I know how to do it.