note 27827 added to function.realpath

From: Date: Thu, 19 Dec 2002 23:49:43 +0000
Subject: note 27827 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-41141@lists.php.net to get a copy of this message
This is a modified version of the code written by Dave, wich finds the absolute path of a virtual path, this function returns the absolute path, If you have php running on IIS Plataform you could find this very usefull function mappath2($path) { //this here bellow trims the last / in case it has it If ($path{strlen($path)-1}=="/"){ $path = substr($path,0, strlen($path)-1); } $relative = str_repeat('../',substr_count($path,'/')-1); // transforms virtual or relative path to an absolute path return realpath(substr($path,0,1)=='/' ? $relative.substr($path,1) : $path); } the implementation would be like this having $imagepath = "/website001/images/catalog/"; $realpath = mappath2($imagepath); The result in $realpath would be something like C:\Inetpub\wwwroot\website001\images\catalog the function can accept either the relative path with or without the ending "/" -------------------------- Edgar Sosa -- http://www.php.net/manual/en/function.realpath.php http://master.php.net/manage/user-notes.php?action=edit+27827 http://master.php.net/manage/user-notes.php?action=delete+27827 http://master.php.net/manage/user-notes.php?action=reject+27827

« previous php.notes (#41141) next »