X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=inc%2Futils.php;h=cee9d9a2a2d7e26650f144e351a214366f7396fc;hp=a0824c8dea4293d218717c16714a3dfecef26edf;hb=2342c1689c6155fc545c372e24dbcac27fcf21e9;hpb=57511b4efd7402ef58de66ac1fe2c01ed1b1d7b5 diff --git a/inc/utils.php b/inc/utils.php index a0824c8..cee9d9a 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -4,6 +4,20 @@ require_once ("inc/settings.php"); +function gethost() { + $host = $_SERVER ["HTTP_HOST"]; + $colpos = strpos ($host, ':'); + // some web clients add port informations in Host header + if ($colpos !== false) { + $host = substr ($host, 0, $colpos); + } + return $host; +} + +function basename_safe ($path) { + return end (explode ("/", $path)); +} + function unquote($gpc_str) { if (!isset ($gpc_str)) { return $gpc_str; @@ -15,13 +29,19 @@ function unquote($gpc_str) { } } -function full_url_from_filename ($filename) { +function full_url_from_imgpath ($filename) { if (defined ("IMGSDIRURL") && (strlen (IMGSDIRURL) != 0)) { return rtrim (IMGSDIRURL, '/') . "/" . rawurlencode ($filename); } $rel_path = UPLOADDIR . "/" . rawurlencode ($filename); + return full_url_from_path (UPLOADDIR . "/" . rawurlencode ($filename)); +} + +function full_url_from_path ($path) { + $rel_path = $path; + while (substr($rel_path, 0, 2) == "./") { // strips ./ $rel_path = substr ($rel_path, 2); } @@ -44,7 +64,7 @@ function full_url_from_filename ($filename) { $path = "$script_dir/$rel_path"; } - $host = $_SERVER ["HTTP_HOST"]; + $host = gethost(); $port = $_SERVER ["SERVER_PORT"]; if ($_SERVER ["HTTPS"] == "on") { $proto = "https"; @@ -61,5 +81,4 @@ function full_url_from_filename ($filename) { return "$proto://$host$port$path"; } - ?>