note 33011 deleted from function.realpath by aidan

From: Date: Sun, 29 Aug 2004 21:50:41 +0000
Subject: note 33011 deleted from function.realpath by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75611@lists.php.net to get a copy of this message
Note Submitter: john [at] stuckeyonline [dot] com ---- for some reason or another, i couldn't get realpath to work. so i made my own. it's very simple, but it does work. it checks vs. the current directory (the one from which the script is being run). --John ====== function myRealPath($path) { // Check if path begins with "/". 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); else array_push($currentDir,$dir); } // Return the slashes. $path = implode($currentDir,"/"); } return $path; }

« previous php.notes (#75611) next »