]> git.p6c8.net - jirafeau.git/commitdiff
[BUGFIX] Manage PHP configuration with "unlimited" upload
authorJerome Jutteau <jerome@jutteau.fr>
Mon, 4 Jul 2022 21:38:25 +0000 (23:38 +0200)
committerJerome Jutteau <jerome@jutteau.fr>
Mon, 4 Jul 2022 21:44:41 +0000 (23:44 +0200)
Setting `post_max_size` and `upload_max_filesize` PHP options to "0" is unmanaged by Jirafeau.
It tries to send 0 bytes and Javascript have some zero division errors.

This commit will use $max_upload_chunk_size_bytes option when available.
If $max_upload_chunk_size_bytes is also set to zero, chunk size is set an arbitrary value of 10M.

Non html-5 users will not have size limitation shown.

fixes #272

Signed-off-by: Jerome Jutteau <jerome@jutteau.fr>
index.php
lib/functions.php

index 1a8b2bdce93d946bb915c6665388bca88295a815..33bb83ea6d34fbfd0e3284bf1712796a605bfdd9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -299,8 +299,11 @@ elseif (true === jirafeau_challenge_upload_ip($cfg, get_ip_address($cfg))) {
     document.getElementById('send').style.display = 'none';
     if (!check_html5_file_api ())
         document.getElementById('max_file_size').innerHTML = '<?php
     document.getElementById('send').style.display = 'none';
     if (!check_html5_file_api ())
         document.getElementById('max_file_size').innerHTML = '<?php
-             echo t('NO_BROWSER_SUPPORT') . jirafeau_get_max_upload_size();
-             ?>';
+            $max_size = jirafeau_get_max_upload_size();
+            if ($max_size > 0) {
+                echo t('NO_BROWSER_SUPPORT') . $max_size;
+            }
+        ?>';
 
     addCopyListener('upload_link_button', 'upload_link');
     addCopyListener('preview_link_button', 'preview_link');
 
     addCopyListener('upload_link_button', 'upload_link');
     addCopyListener('preview_link_button', 'preview_link');
index 536bfe1bcd0d423b80a215d07fb7210ea218d178..cfc7dce8250f58c1debeec5e23477d97dca71c74 100644 (file)
@@ -235,13 +235,23 @@ function jirafeau_get_max_upload_size()
  */
 function jirafeau_get_max_upload_chunk_size_bytes($max_upload_chunk_size_bytes = 0)
 {
  */
 function jirafeau_get_max_upload_chunk_size_bytes($max_upload_chunk_size_bytes = 0)
 {
-    if ($max_upload_chunk_size_bytes > 0) {
-        return min(
-            jirafeau_get_max_upload_size_bytes(),
-            $max_upload_chunk_size_bytes
-        );
+    if ($max_upload_chunk_size_bytes == 0) {
+        $size = jirafeau_get_max_upload_size_bytes();
+        // Jirafeau must choose an arbitrary number as PHP config does not give any limit nor $max_upload_chunk_size_bytes
+        if ($size == 0) {
+            return 10000000; // 10MB
+        }
+        return $size;
     }
     }
-    return jirafeau_get_max_upload_size_bytes();
+
+    $size = min(
+        jirafeau_get_max_upload_size_bytes(),
+        $max_upload_chunk_size_bytes
+    );
+    if ($size == 0) {
+        return $max_upload_chunk_size_bytes;
+    }
+    return $size;
 }
 
 /**
 }
 
 /**

patrick-canterino.de