public static calculate_relative_path ( $file, $returnDir = false ) : string | ||
$file | string The file to calculate the relative path of | |
$returnDir | bool If set to true, only return the dirname | |
Результат | string |
public static function calculate_relative_path($file, $returnDir = false)
{
// We find the document root of the webserver
$doc_root = $_SERVER['DOCUMENT_ROOT'];
// Remove the document root, from the FULL absolute path of the
// file we're looking for
$ret = "/" . str_replace($doc_root, "", $file, $ok);
if (!$ok) {
return false;
}
// If they want the path to the dir, only return the dir part
if ($returnDir) {
$ret = dirname($ret) . "/";
}
$ret = preg_replace("|//|", "/", $ret);
return $ret;
}
public static function get_icon($name, $title) { $path = dirname(__FILE__) . "/icons/{$name}.png"; $rel = Krumo::calculate_relative_path($path); $ret = "<img style=\"padding: 0 2px 0 2px\" src=\"{$rel}\" title=\"{$title}\" alt=\"name\" />"; return $ret; }