calculating psysical path (a first try)

From: Date: Thu, 01 Aug 2002 07:42:47 +0000
Subject: calculating psysical path (a first try)
Groups: php.general 
Request: Send a blank email to php-general+get-110633@lists.php.net to get a copy of this message
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 (lasso@lassoweb.nu)

« previous php.general (#110633) next »