update page now

Voting

: five minus four?
(Example: nine)

The Note You're Voting On

pulstar at ig dot com dot br
21 years ago
Sometimes you may need to refer to the absolute path of a file in your website instead of a relative path, but the realpath() function returns the path relative to the server's filesystem, not a path relative to your website root directory. 
For example, realpath() may return something like this:
/home/yoursite/public_html/dir1/file.ext
You can't use this in an HTML document, because the web server will not find the file. To do so, you can use:
<?php
function htmlpath($relative_path) {
 $realpath=realpath($relative_path);
 $htmlpath=str_replace($_SERVER['DOCUMENT_ROOT'],'',$realpath);
 return $htmlpath;
}
echo '<img src="',htmlpath('../../relative/path/to/file.ext'),'" border=1>'; 
?>

It will return something like:
<img src="/dir1/relative/path/to/file.ext" border=1>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /