ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

realpath vs pathinfo

March 05, 2008 6:24am

Subscribe [2]
  • #1 / Mar 05, 2008 6:24am

    xwero

    4145 posts

    In the index.php you can find

    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = str_replace("\\", "/", realpath(dirname(__FILE__))).'/'.$system_folder;
    }

    why not use

    $system_folder = str_replace('\', '/',pathinfo(__FILE__,PATHINFO_DIRNAME)).'/'.$system_folder;

    Is the pathinfo less trustworthy than realpath?

  • #2 / Mar 05, 2008 11:01am

    Michael Wales

    2070 posts

    pathinfo() doesn’t actually verify anything with the file system, it just merely analyzes the string that is passed to it.

    <?php
    print_r(pathinfo('/no/where/file.txt'));
    ?>
    
    /*
    Output:
    Array
    (
        [dirname] => /no/where
        [basename] => file.txt
        [extension] => txt
        [filename] => file
    )
    */
  • #3 / Mar 05, 2008 11:17am

    xwero

    4145 posts

    i think i found out why realpath is used

    Since PHP 4.0.2, __FILE__ always contains an absolute path whereas in older versions it contained relative path under some circumstances.

  • #4 / Mar 05, 2008 11:33am

    Chris Newton

    440 posts

    From the PHP manual: Realpath expands all symbolic links and resolves references to ‘/./’, ‘/../’ and extra ‘/’ characters in the input path . and return the canonicalized absolute pathname.

    As far as I know, pathinfo does not do that.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases