diff --git a/modules/feature-upload.php b/modules/feature-upload.php index e9897af..0606e6f 100644 --- a/modules/feature-upload.php +++ b/modules/feature-upload.php @@ -14,6 +14,20 @@ register_module([ { case "GET": // Send upload page + + if($settings->allow_uploads) + exit(page_renderer::render("Upload - $settings->sitename", "
+ + +
+ + +
+ +
")); + else + exit(page_renderer::render("Error - Upload - $settings->sitename", "

$settings->sitename does not currently have uploads enabled. Go back.

")); + break; case "PUT": @@ -44,4 +58,36 @@ register_module([ } ]); +//// Pair of functions to calculate the actual maximum upload size supported by the server +//// Lifted from Drupal by @meustrus from Stackoverflow. Link to answer: +//// http://stackoverflow.com/a/25370978/1460422 +// Returns a file size limit in bytes based on the PHP upload_max_filesize +// and post_max_size +function file_upload_max_size() +{ + static $max_size = -1; + if ($max_size < 0) { + // Start with post_max_size. + $max_size = parse_size(ini_get('post_max_size')); + // If upload_max_size is less, then reduce. Except if upload_max_size is + // zero, which indicates no limit. + $upload_max = parse_size(ini_get('upload_max_filesize')); + if ($upload_max > 0 && $upload_max < $max_size) { + $max_size = $upload_max; + } + } + return $max_size; +} + +function parse_size($size) { + $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. + $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size. + if ($unit) { + // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. + return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); + } else { + return round($size); + } +} + ?>