Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - equivalent of MapPath in PHP? 1

Status
Not open for further replies.

whinger74

Programmer
Aug 13, 2002
25
GB
Hi,
I'm used to programming in ASP, and my site is hosted with a commercial host.
Can somebody please tell me how can I find out the physical rather than virtual path of file? i.e. in ASP I would use <%=Server.MapPath %>

Thank you anyone!
 
<?php echo $_SERVER['SCRIPT_FILENAME'] ?>

[sub]I REALLY hope that helps.[/sub]
Will
 
Thanks!
<?php echo $_SERVER['PATH_TRANSLATED'] ?> will produce the same result aswell
After a search of php.net I was eventually successful, even though I didn't really know what exactly I was looking for!!
 
whinger74 said:
<?php echo $_SERVER['PATH_TRANSLATED'] ?> will produce the same result aswell

Actually, PATH_TRANSLATED doesn't work in all cases. PATH_TRANSLATED's little brother is called PATH_INFO and basically here's an example of how it works:

Imagine you have a PHP script that lets users download files on the server... but it does additional things like tracking usage and telling them "Your download will start momentarily". The name of your script will be retrieve.php.

To download a file, the requested file is added on to the end of it, for example:
Now the part following retrieve.php--the "/images/bill.jpg" part--is goes into $_SERVER['PATH_INFO'].

Now, $_SERVER['PATH_TRANSLATED'] is that part as an absolute path relative to the document root. In the previous example PATH_TRANSLATED would be something like /var/
But if there is no PATH_INFO in the URL, I guess PATH_TRANSLATED could be the same as SCRIPT_FILENAME, though you shouldn't count on it.

[sub]I REALLY hope that helps.[/sub]
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top