SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php absolute and relative paths with builtin functions

    How do i get relative and absolute paths with global functions and variables. I have seen in cms like wordpress and joomla, whenever we install it, it stores paths in config.php files accurately whether we have installed it in parent domain or in sub-domain.
    I tried but failed to make such function that can extract correct path working for any directory that user is installing my script. Can anybody suggest that?

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    70
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you want your current directory you can use the dirname() function.
    PHP Code:
    echo dirname__FILE__ ) . '<br />';
    // ouput: /home/user/www/htdocs 
    If you want the parent directory:
    PHP Code:
     echo dirnamedirname__FILE__ ) );
    // ouput: /home/user/www 
    Is this what your are looking for?

  3. #3
    SitePoint Member
    Join Date
    Apr 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its fine for internal script usage to include files.
    What about path that generates in URL i.e : http://localhost/mydir/mydir2/abc/myproject/ OR http://abc.mydomain.com/mydir/abc/
    I dont know how wordpress and other cms gets this exactly correct. How can I have such url as I am gonna need it when I will create installer for my script.

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    70
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You can use the $_SERVER array, specifically the $_SERVER['SERVER_NAME'] and the $_SERVER['PHP_SELF'] array keys. If you do a var_dump() on the $_server array you will find a ton of useful information.

    I'm sorry I didn't answer sooner, it was a very long weekend. I didn't even get a chance to turn the computer on.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •