Converting Between Relative and Absolute File Path

To convert a relative path to an absolute file path, use PHP’s realpath() function. This function performs “path math” means translating all the relative locations in a path string to return a complete absolute path.

If we pass “.” as parameter in below example

  1. <?php
  2. $abs_path = realpath(“.”);
  3. echo $abs_path;
  4. ?>

It will result absolute path as below:

“usr/local/apache/htdocs”

If we pass “..” as parameter then

  1. <?php
  2. $abs_path = realpath(“..”);
  3. echo $abs_path;
  4. ?>

It will result absolute path as below:

“usr/local/apache/”

Laeeq

A web developer who has a love for creativity and enjoys experimenting with various techniques in both web design and development. If you would like to be kept up to date with our posts, you can follow us on Twitter, or even by subscribing to our RSS Feed.

Leave a Reply

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

WordPress SEO fine-tune by Meta SEO Pack from Poradnik Webmastera