aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-04-03 19:02:33 +0200
committerGitHub <noreply@github.com>2017-04-03 19:02:33 +0200
commit2109bb9d9a355787f8beea8cbfaed2eb1d53283f (patch)
tree6fd8c8319ece5e7e565f1793318ff63c665daf74 /index.php
parentd9d49b687afcb4c88a88390a7ff30b431ca6be12 (diff)
parentb68134ac1d6a287e3a5003ccde137dd0c7ecdc52 (diff)
downloadShaarli-2109bb9d9a355787f8beea8cbfaed2eb1d53283f.tar.gz
Shaarli-2109bb9d9a355787f8beea8cbfaed2eb1d53283f.tar.zst
Shaarli-2109bb9d9a355787f8beea8cbfaed2eb1d53283f.zip
Merge pull request #800 from ArthurHoaro/hotfix/get-bytes-warning
Fix a warning generated in return_bytes function and refactor it
Diffstat (limited to 'index.php')
-rw-r--r--index.php32
1 files changed, 2 insertions, 30 deletions
diff --git a/index.php b/index.php
index 863d5093..8f26c390 100644
--- a/index.php
+++ b/index.php
@@ -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.
479function 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)
493function 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...).
506if (!isset($_SESSION['tokens'])) $_SESSION['tokens']=array(); // Token are attached to the session. 478if (!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;