note 36544 added to function.realpath

From: Date: Tue, 14 Oct 2003 13:13:01 +0000
Subject: note 36544 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-58570@lists.php.net to get a copy of this message
This is a correction to John's realpath replacement function : function myRealPath($path) { // Check if path begins with "/". => use === with strpos if (strpos($path,"/") === 0) { $path = $_SERVER['DOCUMENT_ROOT'].$path; } else { // Strip slashes and convert to arrays. $currentDir = preg_split("/\//",dirname($_SERVER['PATH_TRANSLATED'])); $newDir = preg_split('/\//',$path); // Drop one directory from the array for each ".."; add one otherwise. foreach ($newDir as $dir) { if ($dir == "..") array_pop($currentDir); elseif ($dir != ".") //test for "." which represents current dir (do nothing in that case) array_push($currentDir,$dir); } // Return the slashes. $path = implode($currentDir,"/"); } return $path; } ---- Manual Page -- http://www.php.net/manual/en/function.realpath.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36544 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36544&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36544&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58570) next »