note 75992 added to function.realpath

From: Date: Tue, 26 Jun 2007 06:55:25 +0000
Subject: note 75992 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-127971@lists.php.net to get a copy of this message
This is my attempt at writing a realpath replacement. I needed to to run some Adobe code on a server with realpath disabled and this seemed to do the job. It is written for a unix server, I suppose it could be made cross platform using DIRECTORY_SEPARATOR. (With thanks to Marc Noirot for his code). function myRealPath($path) { // check if path begins with "/" ie. is absolute // if it isnt concat with script path if (strpos($path,"/") !== 0) { $base=dirname($_SERVER['SCRIPT_FILENAME']); $path=$base."/".$path; } // canonicalize $path=explode('/', $path); $newpath=array(); for ($i=0; $i<sizeof($path); $i++) { if ($path[$i]==='' || $path[$i]==='.') continue; if ($path[$i]==='..') { array_pop($newpath); continue; } array_push($newpath, $path[$i]); } $finalpath="/".implode('/', $newpath); // check then return valid path or filename if (file_exists($finalpath)) { return ($finalpath); } else return FALSE; } ---- Server IP: 203.16.234.90 Probable Submitter: 59.167.128.18 ---- Manual Page -- http://www.php.net/manual/en/function.realpath.php Edit -- https://master.php.net/note/edit/75992 Del: integrated -- https://master.php.net/note/delete/75992/integrated Del: useless -- https://master.php.net/note/delete/75992/useless Del: bad code -- https://master.php.net/note/delete/75992/bad+code Del: spam -- https://master.php.net/note/delete/75992/spam Del: non-english -- https://master.php.net/note/delete/75992/non-english Del: in docs -- https://master.php.net/note/delete/75992/in+docs Del: other reasons-- https://master.php.net/note/delete/75992 Reject -- https://master.php.net/note/reject/75992 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127971) next »