diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-03-10 20:06:01 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-04-03 18:53:43 +0200 |
commit | 84315a3bad02652e5ea26586fab003eaaf467e30 (patch) | |
tree | 6093f77c2af6c57524b7b0a7795089167438f5e5 /index.php | |
parent | d9d49b687afcb4c88a88390a7ff30b431ca6be12 (diff) | |
download | Shaarli-84315a3bad02652e5ea26586fab003eaaf467e30.tar.gz Shaarli-84315a3bad02652e5ea26586fab003eaaf467e30.tar.zst Shaarli-84315a3bad02652e5ea26586fab003eaaf467e30.zip |
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
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 32 |
1 files changed, 2 insertions, 30 deletions
@@ -473,34 +473,6 @@ if (isset($_POST['login'])) | |||
473 | } | 473 | } |
474 | 474 | ||
475 | // ------------------------------------------------------------------------------------------ | 475 | // ------------------------------------------------------------------------------------------ |
476 | // Misc utility functions: | ||
477 | |||
478 | // Convert post_max_size/upload_max_filesize (e.g. '16M') parameters to bytes. | ||
479 | function return_bytes($val) | ||
480 | { | ||
481 | $val = trim($val); $last=strtolower($val[strlen($val)-1]); | ||
482 | switch($last) | ||
483 | { | ||
484 | case 'g': $val *= 1024; | ||
485 | case 'm': $val *= 1024; | ||
486 | case 'k': $val *= 1024; | ||
487 | } | ||
488 | return $val; | ||
489 | } | ||
490 | |||
491 | // Try to determine max file size for uploads (POST). | ||
492 | // Returns an integer (in bytes) | ||
493 | function getMaxFileSize() | ||
494 | { | ||
495 | $size1 = return_bytes(ini_get('post_max_size')); | ||
496 | $size2 = return_bytes(ini_get('upload_max_filesize')); | ||
497 | // Return the smaller of two: | ||
498 | $maxsize = min($size1,$size2); | ||
499 | // FIXME: Then convert back to readable notations ? (e.g. 2M instead of 2000000) | ||
500 | return $maxsize; | ||
501 | } | ||
502 | |||
503 | // ------------------------------------------------------------------------------------------ | ||
504 | // Token management for XSRF protection | 476 | // Token management for XSRF protection |
505 | // Token should be used in any form which acts on data (create,update,delete,import...). | 477 | // Token should be used in any form which acts on data (create,update,delete,import...). |
506 | if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session. | 478 | if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session. |
@@ -1517,7 +1489,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) | |||
1517 | 1489 | ||
1518 | if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) { | 1490 | if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) { |
1519 | // Show import dialog | 1491 | // Show import dialog |
1520 | $PAGE->assign('maxfilesize', getMaxFileSize()); | 1492 | $PAGE->assign('maxfilesize', get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize'))); |
1521 | $PAGE->renderPage('import'); | 1493 | $PAGE->renderPage('import'); |
1522 | exit; | 1494 | exit; |
1523 | } | 1495 | } |
@@ -1527,7 +1499,7 @@ function renderPage($conf, $pluginManager, $LINKSDB) | |||
1527 | // The file is too big or some form field may be missing. | 1499 | // The file is too big or some form field may be missing. |
1528 | echo '<script>alert("The file you are trying to upload is probably' | 1500 | echo '<script>alert("The file you are trying to upload is probably' |
1529 | .' bigger than what this webserver can accept (' | 1501 | .' bigger than what this webserver can accept (' |
1530 | .getMaxFileSize().' bytes).' | 1502 | .get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize')).').' |
1531 | .' Please upload in smaller chunks.");document.location=\'?do=' | 1503 | .' Please upload in smaller chunks.");document.location=\'?do=' |
1532 | .Router::$PAGE_IMPORT .'\';</script>'; | 1504 | .Router::$PAGE_IMPORT .'\';</script>'; |
1533 | exit; | 1505 | exit; |