Login
|
Webmail
|
Let's Chat
Shared Website Hosting
Domain Names
Hosted Email
Shared Website Hosting
Domain Names
Hosted Email
Company Overview
Legal
Brinkster Knowledge Base
KB Home
/
Support
/
Code Snippets
/
PHP Realpath example
PHP Realpath example
Copy and paste this code snippet into your .php page, then view the page in your web browser.
http://yoursite.com/page.php
We suggest using Realpath instead of using an absolute path in your coded applications.
*Note that no edit to the code needs to be made at all to run this demonstration.*
<html>
<head><title>PHP Realpath Demo</title></head>
<body>
<?php
echo "<font face='HELVETICA'><b>PHP Realpath Demonstration</b><br><br>";
echo "The "File.txt" file does not actually exist;unless you created one that is, this is used as a demonstration of how to use realpath.<br>";
echo "For a more dramatic effect, place this file in a sub folder of your website's root folder.<br><br>";
echo "This path will take you to the folder this file is currently running in.<br>";
echo "<table border=0><tr><td><b>PHP Path: </b></td><td>realpath('').'\file.txt';</td></tr>";
echo "<tr><td><b>Output:</b></td><td>".realpath('').'\file.txt'."</td></tr></table>";
echo "<br><br>";
echo "This path will take you to the root of your website.<br>";
echo "<table border=0><tr><td><b>PHP Path: </b></td><td>realpath($_SERVER['DOCUMENT_ROOT']).'\file.txt';</td></tr>";
echo "<tr><td><b>Output:</b></td><td>".realpath($_SERVER['DOCUMENT_ROOT'])."\file.txt</td></tr></table>";
echo "<br><br>For a more detailed explanation of Realpath please visit this <a style=text-decoration:none href='http://www.w3schools.com/php/func_filesystem_realpath.asp'>Helpful originalAttribute=href originalPath='http://www.w3schools.com/php/func_filesystem_realpath.asp'>Helpful originalAttribute=hreforiginalPath='http://www.w3schools.com/php/func_filesystem_realpath.asp'>Helpful Site</a>";
?>
</body>
</html>