Php Code To Display Full Path

Looking for PHP code to display the full web server path to a file?

You will find this script useful when setting cron jobs for example. A lot of websites require that php scripts are run periodically, in order to update data and make the website dynamic. In order to set the cron jobs you need to know the full path of the file on the server.

The code to achieve that is pretty simple:

<?php
$dir = dirname(__FILE__);
echo “<p>The path to the php file youjust loaded in your browser is: ” . $dir . “</p>”;
?>

You will have to create a php script file, let’s say displaypath.php and copy paste the code above in the file.

Once you upload it to your web server, just load the php file in your  browser:

http://www.your-domain.com/displaypath.php

The full path of the directory where this php script is located will be displayed.

Most often, on Apache web servers, the value returned will be /home/[user-name]/public_html/

 

 

Tags :

Leave comment

Your email address will not be published. Required fields are marked *