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 much memory do PHP variables use?
  • Manipulating PHP arrays: push, pop, shift, unshift
  • 10 Super Useful PHP Code Snippets
  • Let’s play with php.ini file Configuration
  • 15+ regular expressions for PHP developers
  •  

     

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