note 83008 deleted from function.realpath by bjori

From: Date: Tue, 06 May 2008 19:56:00 +0000
Subject: note 83008 deleted from function.realpath by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139103@lists.php.net to get a copy of this message
Note Submitter: metala at metala dot org Reason: bad code ---- //There are cases that this function will not handle properly, but it's mostly secure function path_canonicalize($address){ $address = str_replace('\\', '/', $address); $address = str_replace('//', '/', $address); $address = explode('/', $address); $last=-1; foreach ($address as $key => $value){ if ($value == '..') { unset($address[$key],$address[$last]); $last--; } elseif ($value='') unset($address[$key]); else $last=$key; } $address = implode('/', $address); $address = str_replace('./', '', $address); return $address; } //Relative PAth function path_relative($DirPath1,$DirPath2){ $explode1 = explode('/',str_replace('\\','/',$DirPath1)); $elength1 = count($explode1); $explode2 = explode('/',str_replace('\\','/',$DirPath2)); $elength2 = count($explode1); $diff = array_diff($explode1,$explode2); list($min)=each($diff); $relative = str_repeat('../',$elength1-1-$min); $relative.= implode('/',array_slice($explode2,$min)); return $relative; }

« previous php.notes (#139103) next »