From 84315a3bad02652e5ea26586fab003eaaf467e30 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 10 Mar 2017 20:06:01 +0100 Subject: Fix a warning generated in return_bytes function and refactor it It was multiplying a string containing a letter. Moved function to Utils.php and display a human readable limit size --- index.php | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'index.php') diff --git a/index.php b/index.php index 863d5093..8f26c390 100644 --- a/index.php +++ b/index.php @@ -472,34 +472,6 @@ if (isset($_POST['login'])) } } -// ------------------------------------------------------------------------------------------ -// Misc utility functions: - -// Convert post_max_size/upload_max_filesize (e.g. '16M') parameters to bytes. -function return_bytes($val) -{ - $val = trim($val); $last=strtolower($val[strlen($val)-1]); - switch($last) - { - case 'g': $val *= 1024; - case 'm': $val *= 1024; - case 'k': $val *= 1024; - } - return $val; -} - -// Try to determine max file size for uploads (POST). -// Returns an integer (in bytes) -function getMaxFileSize() -{ - $size1 = return_bytes(ini_get('post_max_size')); - $size2 = return_bytes(ini_get('upload_max_filesize')); - // Return the smaller of two: - $maxsize = min($size1,$size2); - // FIXME: Then convert back to readable notations ? (e.g. 2M instead of 2000000) - return $maxsize; -} - // ------------------------------------------------------------------------------------------ // Token management for XSRF protection // Token should be used in any form which acts on data (create,update,delete,import...). @@ -1517,7 +1489,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) { // Show import dialog - $PAGE->assign('maxfilesize', getMaxFileSize()); + $PAGE->assign('maxfilesize', get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize'))); $PAGE->renderPage('import'); exit; } @@ -1527,7 +1499,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) // The file is too big or some form field may be missing. echo ''; exit; -- cgit v1.2.3