note 73194 added to function.realpath
| From: | PatriceVanneufville at osu1 dot php dot net | Date: | Mon, 12 Feb 2007 23:29:05 +0000 |
| Subject: | note 73194 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123295@lists.php.net to get a copy of this message | ||
the precedent function does not work all the time : servers sometimes put a slash '/' at
the end of $_SERVER['DOCUMENT_ROOT']
// transforme un chemin d'image relatif en chemin html absolu
function htmlpath($relative_path) {
$realpath = str_replace("\\", "/", realpath($relative_path));
$root = preg_replace(',/$,', '', $_SERVER['DOCUMENT_ROOT']);
if (strlen($root) && strpos($realpath, $root)===0)
return substr($realpath, strlen($root));
$dir = dirname(!empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] :
(!empty($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] :
(!empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] :
str_replace('\\','/',__FILE__)
)));
return canonicalize($dir.'/'.$relative_path);
}
// retourne un chemin canonique a partir d'un chemin contenant des ../
function canonicalize($address) {
$address = str_replace("//", "/", $address);
$address = explode('/', $address);
$keys = array_keys($address, '..');
foreach($keys as $keypos => $key) array_splice($address, $key - ($keypos * 2 + 1), 2);
$address = implode('/', $address);
return preg_replace(',([^.])\./,', '\1', $address);
}
----
Server IP: 194.246.101.61
Probable Submitter: 82.224.182.49
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- https://master.php.net/note/edit/73194
Del: integrated -- https://master.php.net/note/delete/73194/integrated
Del: useless -- https://master.php.net/note/delete/73194/useless
Del: bad code -- https://master.php.net/note/delete/73194/bad+code
Del: spam -- https://master.php.net/note/delete/73194/spam
Del: non-english -- https://master.php.net/note/delete/73194/non-english
Del: in docs -- https://master.php.net/note/delete/73194/in+docs
Del: other reasons-- https://master.php.net/note/delete/73194
Reject -- https://master.php.net/note/reject/73194
Search -- https://master.php.net/manage/user-notes.php