note 44890 added to function.pathinfo
| From: | junk at plaino dot com | Date: | Thu, 19 Aug 2004 13:41:51 +0000 |
| Subject: | note 44890 added to function.pathinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80068@lists.php.net to get a copy of this message | ||
Convert a URL to the local file path and vice versa, convert a local file path to a URL.
// this sets the sytem / or \ :
strstr( PHP_OS, "WIN") ? $slash = "\\" : $slash = "/";
// This is the location of the php file that contains this
// function. Usually this request is made to files/folders
// down the directory structure, so the php file that
// contains these functions is a good "where am i"
// reference point:
$WIMPY_BASE['path']['physical'] = getcwd();
$WIMPY_BASE['path']['www'] = "http://".$_SERVER['HTTP_HOST'];
function url2filepath($theURL){
global $WIMPY_BASE, $slash;
$AtheFile = explode ("/", $theURL);
$theFileName = array_pop($AtheFile);
$AwimpyPathWWW = explode ("/", $WIMPY_BASE['path']['www']);
$AtheFilePath = array_values (array_diff ($AtheFile, $AwimpyPathWWW));
if($AtheFilePath){
$theFilePath = $slash.implode($slash, $AtheFilePath).$slash.$theFileName;
} else {
$theFilePath = implode($slash, $AtheFilePath).$slash.$theFileName;
}
return ($WIMPY_BASE['path']['physical'].$theFilePath);
}
function filepath2url ($theFilepath){
global $WIMPY_BASE, $slash;
$AtheFile = explode ($slash, $theFilepath);
$theFileName = array_pop($AtheFile);
$AwimpyPathFILE = explode ($slash, $WIMPY_BASE['path']['physical']);
$AtheFilePath = array_values (array_diff ($AtheFile, $AwimpyPathFILE));
$thFileURL = implode("/", $AtheFilePath)."/".$theFileName;
return ($WIMPY_BASE['path']['www']."$thFileURL");
}
----
Manual Page -- http://www.php.net/manual/en/function.pathinfo.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44890
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44890&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44890&report=yes
Search -- http://master.php.net/manage/user-notes.php