note 90337 added to function.realpath

From: Date: Thu, 16 Apr 2009 20:57:58 +0000
Subject: note 90337 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-153409@lists.php.net to get a copy of this message
<?php Class RealPath { private $ServerPath; private $ScriptPath; private $AddSlashEnd; function __construct() { $this->AddSlashEnd = ""; $this->ServerPath = $_SERVER['DOCUMENT_ROOT']; $this->ScriptPath = substr(dirname($_SERVER['SCRIPT_FILENAME']), strlen($this->ServerPath)); } private function Server($adress) { $ThisPath = @realpath($adress); $ThisPathLength = strlen($ThisPath); return substr($ThisPath, strlen($this->ServerPath), $ThisPathLength); } public function Absolute($adress) { return $_SERVER['SERVER_NAME'] . $this->Server($adress) . $this->AddSlashEnd; } public function RelativeServer($adress) { return $this->Server($adress) . $this->AddSlashEnd; } public function RelativeScript($adress) { $ScriptExplode = explode("/", $this->ScriptPath); $ServerExplode = explode("/", $this->Server($adress)); $TmpCount = $ScriptCount = count($ScriptExplode); $ServerCount = count($ServerExplode); $ReturnPath = ""; for($i = 1; $i < $TmpCount; $i++) { if($ScriptExplode[$i] == $ServerExplode[$i]) --$ScriptCount; else break; } for($i = 1; $i < $ScriptCount; $i++) $ReturnPath .= "/.."; for($i = $TmpCount - $ScriptCount + 1; $i < $ServerCount; $i++) $ReturnPath .= "/" . $ServerExplode[$i]; return $ReturnPath . $this->AddSlashEnd; } public function AddSlash($value) { if(is_bool($value)) { $this->AddSlashEnd = ($value)? "/" : ""; return true; } else return false; } } example: $ObjectPath = new RealPath; $ObjectPath->RelativeScript("../a/b../c/d/f../g../h"); ---- Server IP: 64.71.164.2 Probable Submitter: 2002:9c11:e708::9c11:e708 ---- Manual Page -- http://www.php.net/manual/en/function.realpath.php Edit -- https://master.php.net/note/edit/90337 Del: integrated -- https://master.php.net/note/delete/90337/integrated Del: useless -- https://master.php.net/note/delete/90337/useless Del: bad code -- https://master.php.net/note/delete/90337/bad+code Del: spam -- https://master.php.net/note/delete/90337/spam Del: non-english -- https://master.php.net/note/delete/90337/non-english Del: in docs -- https://master.php.net/note/delete/90337/in+docs Del: other reasons-- https://master.php.net/note/delete/90337 Reject -- https://master.php.net/note/reject/90337 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153409) next »