Change language

PHP Realpath () function

|
Syntax:
realpath(path)
Parameters used: PHP’s realpath() function takes only one parameter.
  • path:is a required parameter that specifies the symbolic path for which the user wants to know the absolute path.
Returned value:
It returns the absolute path to the file on success and False on failure.Errors and exceptions
  • The realpath() function returns False if the running script does not have execute permissions for all directories in the hierarchy.
  • The realpath() function will not work for a file which is inside a Phar, since such a path is not a real path.
  • Some filesystem functions may return unexpected results for files larger than 2 GB, because the PHP integer type is signed and many platforms use 32-bit prices. numbers.
  • Examples:
    Input: echo realpath ("gfg.txt"); Output: C: xampphtdocsfilehandlinggfg.txt Input: chdir (’/ docs / assignment /’); echo realpath (’./../../ gfg / articles’); Output: / gfg / articles 
    The programs below illustrate the realpath() function.Suppose there is a file named "gfg.txt"Program 1
    // return the absolute path
    // using the realpath() function echo realpath ( " gfg.txt " );  
    ?>
    Output:
    C: xampphtdocsfilehandlinggfg.txt 
    Program 2  
    // use chdir() to change directory chdir ( ’/ docs / assignment /’ );  
    // return the absolute path using the realpath() function echo realpath ( ’./../../ gfg / articles’ );  
    ?>
    Output:
    / gfg / articles 
    Link:
    http://php.net/manual/en/function.realpath.php