note 48361 added to function.realpath

From: Date: Mon, 20 Dec 2004 21:43:27 +0000
Subject: note 48361 added to function.realpath
Groups: php.notes 
Request: Send a blank email to php-notes+get-82098@lists.php.net to get a copy of this message
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> ---- Manual Page -- http://www.php.net/manual/en/function.realpath.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48361 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48361&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48361&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48361&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48361&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48361&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48361&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48361&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82098) next »