From: Roland Häder Date: Thu, 31 Mar 2016 07:20:04 +0000 (+0200) Subject: Introduced detectServerUrl() which makes configuration of static 'url' X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a7a3f3ce5e4ef8a50bb0829f7a000f9af867b322;p=simple-upload.git Introduced detectServerUrl() which makes configuration of static 'url' automatic. --- diff --git a/index.php b/index.php index 9d8a4e8..883405c 100644 --- a/index.php +++ b/index.php @@ -59,8 +59,8 @@ // Display debugging information 'debug' => false, - // Complete URL to your directory (including tracing slash) - 'url' => 'http://strace.club/', + // Complete URL to your directory (including tracing slash, leave for auto-detection) + 'url' => detectServerUrl(), // Amount of seconds that each file should be stored for (0 for no limit) // Default 30 days @@ -99,7 +99,7 @@ $data = array(); // Name of this file - $data['scriptname'] = $settings['url'] . '/' . pathinfo(__FILE__, PATHINFO_BASENAME); + $data['scriptname'] = $settings['url'] . pathinfo(__FILE__, PATHINFO_BASENAME); // Adding current script name to ignore list $data['ignores'] = $settings['ignores']; @@ -246,6 +246,27 @@ return (is_file($file) && is_readable($file)); } + // Detects full URL of installation + function detectServerUrl () { + // Is "cache" there? + if (!isset($GLOBALS[__FUNCTION__])) { + // Default protocol is HTTP + $protocol = 'http'; + + // Is SSL given? + if (((isset($_SERVER['HTTPS'])) && (strtolower($_SERVER['HTTPS']) == 'on')) || ((isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) && (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'))) { + // Protocol is HTTPS + $protocol = 'https'; + } // END - if + + // Construct full URL + $GLOBALS[__FUNCTION__] = str_replace("\\", '', sprintf('%s://%s%s/', $protocol, $_SERVER['SERVER_NAME'], dirname($_SERVER['SCRIPT_NAME']))); + } // END - if + + // Return cached value + return $GLOBALS[__FUNCTION__]; + } + // Files are being POSEed. Uploading them one by one. if (isset($_FILES['file'])) { header('Content-type: text/plain');