regarding ASP's Server.Mappath
Posted: Thu Dec 23, 2010 9:00 am
I see a lot of discussion of programmers looking for a PHP equivalent to ASP's server.mapPath.
There isn't one. I wish there was.
There are things that look like they are the same, such as realpath or $_SERVER["path_translated"], but they only work against paths that are real and/or relative to the root path of the document. Consider this case:
STRUCTURE ON DISC
-
STRUCTURE IN IIS
-
Thus, all websites share a common root, with their individual files broken up in virtual directories. Using server.mappath, I can get the physical path to \wImages for any customer's website: if I'm on customer_one's website, using a file in d:\inetpub\myWebApp, server.mappath("\wimages") returns d:\inetpub\customer_one\userdata\images.
Because "\wImages" is a virtual path, not relative to the application root, realpath returns an empty string, as does path_translated.
Discussion?
- Bill in Kansas City, Mo, USA
http://www.mapsedgemedia.com
Measure with a micrometer. Mark with a crayon. Cut with an ax.
There isn't one. I wish there was.
There are things that look like they are the same, such as realpath or $_SERVER["path_translated"], but they only work against paths that are real and/or relative to the root path of the document. Consider this case:
STRUCTURE ON DISC
-
Code: Select all
d:\
.\inetpub
.\customer_one
.\templates
.\userdata
.\images
.\sounds
.\video
.\html
.\customer_two
.\templates
.\userdata
.\images
.\sounds
.\video
.\html
.\customer_...n
.\templates
.\userdata
.\images
.\sounds
.\video
.\html
.\myWebAppSTRUCTURE IN IIS
-
Code: Select all
IIS
.\websites
.\customer_one
.\{root} >> d:\inetpub\myWebApp
.\{virtual}wImages >> d:\inetpub\customer_one\userdata\images
.\{virtual}wSounds >> d:\inetpub\customer_one\userdata\images
.\{virtual}wVideo >> d:\inetpub\customer_one\userdata\images
.\{virtual}wHTML >> d:\inetpub\customer_one\userdata\images
.\{virtual}wTemplates >> d:\inetpub\customer_one\templates
.\customer_two
.\{root} >> d:\inetpub\myWebApp
.\{virtual}wImages >> d:\inetpub\customer_two\userdata\images
.\{virtual}wSounds >> d:\inetpub\customer_two\userdata\images
.\{virtual}wVideo >> d:\inetpub\customer_two\userdata\images
.\{virtual}wHTML >> d:\inetpub\customer_two\userdata\images
.\{virtual}wTemplates >> d:\inetpub\customer_two\templatesThus, all websites share a common root, with their individual files broken up in virtual directories. Using server.mappath, I can get the physical path to \wImages for any customer's website: if I'm on customer_one's website, using a file in d:\inetpub\myWebApp, server.mappath("\wimages") returns d:\inetpub\customer_one\userdata\images.
Because "\wImages" is a virtual path, not relative to the application root, realpath returns an empty string, as does path_translated.
Discussion?
- Bill in Kansas City, Mo, USA
http://www.mapsedgemedia.com
Measure with a micrometer. Mark with a crayon. Cut with an ax.