note 80652 added to function.pathinfo
| From: | OakBehringer at osu1 dot php dot net | Date: | Mon, 28 Jan 2008 01:47:45 +0000 |
| Subject: | note 80652 added to function.pathinfo | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135445@lists.php.net to get a copy of this message | ||
Building on David Blinco's function, the following will:
1. Return the correct protocol for secure requests (https)
2. Throw an exception for invalid files
3. Ensure the returned url separates directories with forward slashes (David's will not on
Windows systems).
function mapPath ($filepath) {
$realpath = realpath($filepath);
$dir;
// Verify that the path passed is real and harvest the bottom directory
if (is_file($realpath)) {
$dir = dirname($realpath);
}
elseif (is_dir($realpath)) {
$dir = $realpath;
}
else {
throw new Exception('File does not exist: ' . $realpath);
}
// Make sure the path is not lower than the server root
if (strlen($dir) < strlen($_SERVER['DOCUMENT_ROOT']))
throw new Exception("Cannot create http path below server http root.");
$path = ((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !=
'off') ? 'https' : 'http') . '://' .
$_SERVER['HTTP_HOST'] . substr($realpath, strlen($_SERVER['DOCUMENT_ROOT']));
if (DIRECTORY_SEPARATOR == '\\')
$path = str_replace('\\', '/', $path);
return $path;
}
----
Server IP: 208.69.120.35
Probable Submitter: 98.206.203.207
----
Manual Page -- http://www.php.net/manual/en/function.pathinfo.php
Edit -- https://master.php.net/note/edit/80652
Del: integrated -- https://master.php.net/note/delete/80652/integrated
Del: useless -- https://master.php.net/note/delete/80652/useless
Del: bad code -- https://master.php.net/note/delete/80652/bad+code
Del: spam -- https://master.php.net/note/delete/80652/spam
Del: non-english -- https://master.php.net/note/delete/80652/non-english
Del: in docs -- https://master.php.net/note/delete/80652/in+docs
Del: other reasons-- https://master.php.net/note/delete/80652
Reject -- https://master.php.net/note/reject/80652
Search -- https://master.php.net/manage/user-notes.php