summaryrefslogtreecommitdiff
path: root/inc/init.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2007-09-30 23:49:58 +0200
committerAndreas Gohr <andi@splitbrain.org>2007-09-30 23:49:58 +0200
commitef38bfe8bb5e72af7ca6f9b442f1d95dfb1d1e0b (patch)
tree1299c650a08fe68b621a9b53e7dab7f59327c015 /inc/init.php
parentd0a27cb03cdfea95e402e7896ea446c4d45b5942 (diff)
downloadrpg-ef38bfe8bb5e72af7ca6f9b442f1d95dfb1d1e0b.tar.gz
rpg-ef38bfe8bb5e72af7ca6f9b442f1d95dfb1d1e0b.tar.bz2
fullpath fix for Windows
darcs-hash:20070930214958-7ad00-bc8ca26f86ea4c9e68ea2b8f3cacc2a598543122.gz
Diffstat (limited to 'inc/init.php')
-rw-r--r--inc/init.php18
1 files changed, 11 insertions, 7 deletions
diff --git a/inc/init.php b/inc/init.php
index f96997f21..354c0f0a4 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -410,10 +410,13 @@ EOT;
* @link http://de3.php.net/manual/en/function.realpath.php#75992
*/
function fullpath($path){
+ $iswin = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
+ if($iswin) $path = str_replace('\\','/',$path); // windows compatibility
- // check if path begins with "/" ie. is absolute
+ // check if path begins with "/" or "c:" ie. is absolute
// if it isnt concat with script path
- if (strpos($path,"/") !== 0) {
+ if ((!$iswin && $path{0} !== '/') ||
+ ($iswin && $path{1} !== ':')) {
$base=dirname($_SERVER['SCRIPT_FILENAME']);
$path=$base."/".$path;
}
@@ -421,15 +424,16 @@ function fullpath($path){
// canonicalize
$path=explode('/', $path);
$newpath=array();
- for ($i=0; $i<sizeof($path); $i++) {
- if ($path[$i]==='' || $path[$i]==='.') continue;
- if ($path[$i]==='..') {
+ foreach($path as $p) {
+ if ($p === '' || $p === '.') continue;
+ if ($p==='..') {
array_pop($newpath);
continue;
}
- array_push($newpath, $path[$i]);
+ array_push($newpath, $p);
}
- $finalpath="/".implode('/', $newpath);
+ $finalpath = implode('/', $newpath);
+ if(!$iswin) $finalpath = '/'.$finalpath;
// check then return valid path or filename
if (file_exists($finalpath)) {