diff options
-rw-r--r-- | app/class/Controllermedia.php | 2 | ||||
-rw-r--r-- | app/fn/fn.php | 36 | ||||
-rw-r--r-- | app/view/templates/media.php | 2 | ||||
-rw-r--r-- | app/view/templates/mediamenu.php | 5 |
4 files changed, 44 insertions, 1 deletions
diff --git a/app/class/Controllermedia.php b/app/class/Controllermedia.php index 0d75de7..678f28e 100644 --- a/app/class/Controllermedia.php +++ b/app/class/Controllermedia.php @@ -48,6 +48,8 @@ class Controllermedia extends Controller $pathlist = []; $this->mediamanager->listpath($dirlist, '', $pathlist); + $vars['maxuploadsize'] = readablesize(file_upload_max_size()) . 'o'; + if (isset($_GET['display'])) { $this->session->addtosession('mediadisplay', $_GET['display']); } diff --git a/app/fn/fn.php b/app/fn/fn.php index 103062a..e0e5f47 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -433,3 +433,39 @@ function accessfile(string $path, bool $createdir = false): bool return false; } } + +// 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. + $post_max_size = parse_size(ini_get('post_max_size')); + if ($post_max_size > 0) { + $max_size = $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. + $size = floatval($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); + } +} diff --git a/app/view/templates/media.php b/app/view/templates/media.php index ea87fba..42654db 100644 --- a/app/view/templates/media.php +++ b/app/view/templates/media.php @@ -10,7 +10,7 @@ $this->layout('layout', ['title' => 'media', 'stylesheets' => [$css . 'home.css' <?php $this->insert('backtopbar', ['user' => $user, 'tab' => 'media', 'pagelist' => $pagelist]) ?> -<?php $this->insert('mediamenu', ['user' => $user, 'pathlist' => $pathlist, 'mediaopt' => $mediaopt]) ?> +<?php $this->insert('mediamenu', ['user' => $user, 'pathlist' => $pathlist, 'mediaopt' => $mediaopt, 'maxuploadsize' => $maxuploadsize]) ?> <main class="media"> diff --git a/app/view/templates/mediamenu.php b/app/view/templates/mediamenu.php index f79b2bc..37598a0 100644 --- a/app/view/templates/mediamenu.php +++ b/app/view/templates/mediamenu.php @@ -7,6 +7,11 @@ <form id=addmedia action="<?= $this->url('mediaupload') ?>" method="post" enctype="multipart/form-data"> <label for="file">🚀 Upload file(s)</label> <input type='file' id="file" name='file[]' multiple required> + + <p> + Max upload size : <?= $maxuploadsize ?> + </p> + <input type="hidden" name="dir" value="<?= $mediaopt->dir() ?>"> <input type="submit" value="upload"> </form> |