Page 1 of 1

regarding ASP's Server.Mappath

Posted: Thu Dec 23, 2010 9:00 am
by mapsedge
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
-

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
		.\myWebApp

STRUCTURE 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\templates


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.

Re: regarding ASP's Server.Mappath

Posted: Thu Dec 23, 2010 7:40 pm
by requinix
PHP doesn't know about the server configuration. ASP.NET does.

You can always do a realpath() relative to the current file with

Code: Select all

realpath(dirname(__FILE__) . "/wimages")
Also keep in mind that .NET is a framework. It's not fair to say that PHP is missing a Server.MapPath equivalent because that method is provided by a framework, not the language itself.
If you want to complain that Zend Framework or Symfony doesn't have an equivalent, go right ahead.

Re: regarding ASP's Server.Mappath

Posted: Fri Dec 24, 2010 1:43 am
by Christopher
A lot of what you are discussing is web server related -- not related to PHP. Using Apache for example, you could certainly make the server directories look like that, or any other layout you'd like. Likewise you can have virtual directories if you want as well. And on Unix the use of symbolic links is much more common. DOS/Windows still has those silly drive letters, whereas Unix has been mounting filesystems anywhere under / that you want forever.

Likewise from my understanding of server.mapPath, you are asking for something that is not necessary in the Apache/PHP way of thinking. The paths to everything are available for you to do with as you wish. See phpinfo() for what is available on your installation.

Re: regarding ASP's Server.Mappath

Posted: Wed Mar 30, 2011 9:57 am
by mapsedge
tasairis wrote:PHP doesn't know about the server configuration. ASP.NET does.
That's sort of the point.
tasairis wrote:Also keep in mind that .NET is a framework. It's not fair to say that PHP is missing a Server.MapPath equivalent because that method is provided by a framework, not the language itself.
Just to be clear, I'm working in classic ASP, not {insert flavor of the day}.NET, thus NOT a framework...And it is absolutely fair to say that "PHP is missing a server.mapPath equivalent" because it is. PHP has a parser the same as ASP does: php5isapi.dll (in our case) <=> asp.dll, and should (seems logical to me) have access to the same information. As noted in my original post, there are two similar functions, but they don't accomplish exactly the same thing.
tasairis wrote:If you want to complain that Zend Framework or Symfony doesn't have an equivalent, go right ahead.
Relax, please. I'm migrating to PHP as a matter of choice, not mandate, so I have as much reason to appreciate the benefits as anyone on here. But as with any transition, there will always be frustrations on the way. For any other ASP programmers also making the change or adding to the toolbox, they need to know that some functions just aren't available.

Re: regarding ASP's Server.Mappath

Posted: Wed Mar 30, 2011 10:01 am
by mapsedge
Christopher wrote:Likewise from my understanding of server.mapPath, you are asking for something that is not necessary in the Apache/PHP way of thinking. The paths to everything are available for you to do with as you wish. See phpinfo() for what is available on your installation.
Only physical, real paths are available, which - for the benefit of other ASP programmers who are going through this transition - is the point I'm trying to make. Not that PHP is deficient in some way, but that some of the crutches we've been walking on aren't available.