Converting Between Relative and Absolute File Path

March 2nd, 2013 by Laeeq | No comments

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/”

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • How to Remove Leading & Trailing White Spaces with PHP
  • Parse HTML/Web Pages with PHP
  • Block Multiple IP Addresses Using PHP
  • How much memory do PHP variables use?
  • Manipulating PHP arrays: push, pop, shift, unshift
  •  

     

    1. No comments yet.
    1. No trackbacks yet.