X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=index.php;h=883405c9a6da38d97e69066d9ed517e2787fe01a;hb=a7a3f3ce5e4ef8a50bb0829f7a000f9af867b322;hp=e32486df394cb1f9427da0cc6021cc92e9fa6196;hpb=2c6a6b1ac520a2932f55eabc493dc5a2dc18cd27;p=simple-upload.git diff --git a/index.php b/index.php index e32486d..883405c 100644 --- a/index.php +++ b/index.php @@ -20,7 +20,13 @@ // Website title 'title' => 'strace.club', - // Directory to store uploaded files + // Description for this website + 'description' => '', + + // Base path (auto-detection) + 'base_path' => dirname(__FILE__) . DIRECTORY_SEPARATOR, + + // Directory to store uploaded files (relative to base_path) 'uploaddir' => '.', // Display list uploaded files @@ -53,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 @@ -93,14 +99,14 @@ $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']; $data['ignores'][] = basename($data['scriptname']); // Use canonized path - $data['uploaddir'] = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . $settings['uploaddir']); + $data['uploaddir'] = realpath($settings['base_path'] . $settings['uploaddir']); // Maximum upload size, set by system $data['max_upload_size'] = ini_get('upload_max_filesize'); @@ -185,16 +191,20 @@ // Do now allow to overwriting files if (isReadableFile($file_data['upload_target_file'])) { echo 'File name already exists' . "\n"; - return; + return false; } // Moving uploaded file OK if (move_uploaded_file($file_data['tmp_name'], $file_data['upload_target_file'])) { - if ($settings['allow_deletion'] || $settings['allow_private']) + if ($settings['listfiles'] && ($settings['allow_deletion'] || $settings['allow_private'])) $_SESSION['upload_user_files'][] = $file_data['target_file_name']; echo $settings['url'] . $file_data['target_file_name'] . "\n"; + + // Return target file name for later handling + return $file_data['upload_target_file']; } else { echo 'Error: unable to upload the file.'; + return false; } } @@ -236,15 +246,38 @@ 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'); if (is_array($_FILES['file'])) { $file_array = diverseArray($_FILES['file']); - foreach ($file_array as $file_data) - uploadFile($file_data); - } else - uploadFile($_FILES['file']); + foreach ($file_array as $file_data) { + $targetFile = uploadFile($file_data); + } + } else { + $targetFile = uploadFile($_FILES['file']); + } exit; } @@ -262,15 +295,19 @@ global $data; $file_array = array(); + $dh = opendir($dir); - while ($filename = readdir($dh)) { - $fqfn = $dir . DIRECTORY_SEPARATOR . $filename; - if (isReadableFile($fqfn) && !in_array($filename, $data['ignores'])) - $file_array[filemtime($fqfn)] = $filename; - } + + while ($filename = readdir($dh)) { + $fqfn = $dir . DIRECTORY_SEPARATOR . $filename; + if (isReadableFile($fqfn) && !in_array($filename, $data['ignores'])) + $file_array[filemtime($fqfn)] = $filename; + } ksort($file_array); + $file_array = array_reverse($file_array, true); + return $file_array; } @@ -412,6 +449,7 @@

+

Maximum upload size: