Guides

Finding the physical path to a website

Several methods can be used to extract the physical path of the files of a website, such as scripts in ASP or PHP language.

  • ASP script

    The MapPath method of the Server object can be used to retrieve the physical path of the root of a website with ASP, as in the following example:

    <% Response.write(Server.MapPath("/")) %>

  • PHP script

    The realpath function is used to obtain the absolute physical path of the current location with PHP. Simply create a script with this line

    <?php echo realpath("."); ?>

    To obtain only the root of the website, regardless of where the script is located:

    <?php preg_match("/.*nomedominio\.estensione/",realpath("."), $risultato); ?>

In both cases the response will be like:
- Windows server: unità:percorso-fisico\nomedominio.estensione
- Linux server: /percorso-fisico/nomedominio.estensione