Results 1 to 10 of 10

Thread: Server.MapPath - PHP equivalent?

  1. #1

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141

    Server.MapPath - PHP equivalent?

    Is there a function (or has someone else written one) that does the equivalent of ASP's Server.MapPath?

    I know there are a few that will sort of do it, but quite often they will return stuff like ../../../../whatever - which is pretty much useless for my purposes! I'm after the full path on the local file system.

    Say there is a page on a website named "index.html"...I'd like a function that would convert that to "/usr/local/home/httpd/htdocs/index.html" or "c:\apache\htdocs\index.html".

    Any ideas?

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    PHP Code:
    echo realpath(substr($PHP_SELF1));

    //or

    echo realpath("index.php"); 
    Hope it helps

  3. #3
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    or

    echo $_ENV["SCRIPT_FILENAME"];

    or

    echo $_SERVER["SCRIPT_FILENAME"];

    does the samething.

    and Da_Silvy, $PHP_SELF has pretty much gone to the wayside if used by itself.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  4. #4

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    Thanks, da_silvy. That was just the function I needed. Funny, I looked right through the filesystem section in the PHP help file but never saw that one staring me in the face!!



    scoutt, normally those would be fine, but I needed to know the full path of a file that would not necessarily be the PHP script currently executing. I needed it for a little security precaution - a page on the site was going to be including other files from paths provided in the query string - I needed to make sure that the file to be included was actually within the website and not some other file like /etc/passwd...the contents of which would be then shown to the end user
    BTW, did you loose your VB Forums account aswell?

  5. #5
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    yes I did and they haven't added it back as of yet.

    ahh I see what you are doing.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  6. #6

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    Who's the cheeky chappy on your avatar?
    Something else I seem to have lost.

  7. #7
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    that is sully from Monsters Inc.

    don't know if you have found the thread in the feedback forum, but you can ask for your posts and stuff back. just give a jingle in that thread and show where you have posted that says guest and not yet registered.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  8. #8
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    Originally posted by mralston
    Thanks, da_silvy. That was just the function I needed. Funny, I looked right through the filesystem section in the PHP help file but never saw that one staring me in the face!!



    scoutt, normally those would be fine, but I needed to know the full path of a file that would not necessarily be the PHP script currently executing. I needed it for a little security precaution - a page on the site was going to be including other files from paths provided in the query string - I needed to make sure that the file to be included was actually within the website and not some other file like /etc/passwd...the contents of which would be then shown to the end user
    BTW, did you loose your VB Forums account aswell?
    no worries

  9. #9

    Thread Starter
    Addicted Member mralston's Avatar
    Join Date
    Aug 2002
    Location
    Altrincham Nr Manchester, England
    Posts
    141
    Originally posted by scoutt
    that is sully from Monsters Inc.

    don't know if you have found the thread in the feedback forum, but you can ask for your posts and stuff back. just give a jingle in that thread and show where you have posted that says guest and not yet registered.
    D'ya know, I think I've asked you that before, Scoutt. Sudden deja vu when I just read your reply.

    Mmmm...a post in that thread, I have made.

  10. #10
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    probably, it does sound familiar.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

Posting Permissions

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



Click Here to Expand Forum to Full Width