note 52787 added to function.realpath
| From: | Santa at osu1 dot php dot net | Date: | Thu, 12 May 2005 13:07:07 +0000 |
| Subject: | note 52787 added to function.realpath | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89330@lists.php.net to get a copy of this message | ||
The htmlpath function suggested beforehand can be useful, but causes problems on (my) webserver
under windows. My apache gives me backslashes in the $_SERVER['DOCUMENT_ROOT'] variable,
but normal slashes in any path given back by the realpath() function. So the str_replace function
doesn't work.
Possible solution: Ensure the use of the same slashes by using
realpath($_SERVER['DOCUMENT_ROOT']) instead of $_SERVER['DOCUMENT_ROOT'] only.
So the example looks like:
<?php
function htmlpath($relative_path) {
$realpath = realpath($relative_path);
$htmlpath = str_replace(realpath($_SERVER['DOCUMENT_ROOT']),'',$realpath);
return $htmlpath;
}
echo '<img src="', htmlpath('../../relative/path/to/file.ext'),
'" border=1>';
?>
----
Manual Page -- http://www.php.net/manual/en/function.realpath.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52787
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52787&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52787&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52787&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52787&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52787&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52787&report=yes
Search -- http://master.php.net/manage/user-notes.php