Hi list!

Something I use quite often when programming in ASP is the 
Server.MapPath method. This method expects a virtual path (on the web 
server) and returns the corresponding psysical path. I haven't seen this 
anywhere in PHP, so I've hacked my own little routine to do this (see 
below). But I still have two questions:

a) Is there perhaps a built-in function I can use instead? I browsed 
through the manual quite a lot, but I haven't found quite like this.

b) If there isn't a built-in function, perhaps you could help me make my 
function better? It seems I use a lot of code for this TINY problem...

Here's the function:
<snip>
// This function calculates the physical path for a given virtual path.
function map_path($virtual_path) {
   // Deklarera necessary variables as global
   global $HTTP_SERVER_VARS;

   // Find out where this file is located in the psysical file system
   $script_filename = $HTTP_SERVER_VARS["SCRIPT_FILENAME"];

   // Find out where this file is located in the virtual file system
   $script_name = $HTTP_SERVER_VARS["SCRIPT_NAME"];

   // Calculate which folder in the psysical filesystem that corresponds
   // to the root folder in the virtual filesystem
   $psychical_root = substr($script_filename, 0, strlen($script_filename)
     - strlen($script_name));

   // Calculate which folder in the psysical filesystem that corresponds
   // to the given folder in the virtual filesystem
   $psychical_path = $psychical_root . $virtual_path;

   return $psychical_path;
}
</snip>

Kindly

/Lasso ([EMAIL PROTECTED])


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to