note 27827 deleted from function.realpath by aidan
| From: | aidan@php.net | Date: | Sun, 29 Aug 2004 21:51:38 +0000 |
| Subject: | note 27827 deleted from function.realpath by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-75619@lists.php.net to get a copy of this message | ||
Note Submitter: esosa at econtacto dot net
----
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