]> git.mxchange.org Git - friendica.git/commitdiff
Added check if upload_max_filesize (php.ini) or friendica option 'maxfilesize' is...
authorMarek Bachmann <marek.bachmann@comtec.eecs.uni-kassel.de>
Fri, 25 Nov 2022 21:57:06 +0000 (22:57 +0100)
committerMarek Bachmann <marek.bachmann@comtec.eecs.uni-kassel.de>
Fri, 25 Nov 2022 21:57:06 +0000 (22:57 +0100)
mod/photos.php

index a78f8d10128d9cafbf92f1101e6f28b71108f30d..f6ed55793b49fe8126a5703b5abc11a3f81ff52f 100644 (file)
@@ -914,9 +914,47 @@ function photos_content(App $a)
                        '$submit' => DI::l10n()->t('Submit'),
                ]);
 
-               $maximagesize_bytes = DI::config()->get('system', 'maximagesize');
-               $maximagesize_Mbytes = ($maximagesize_bytes / (10**6));
+               /* This block determines which setting actually limits  upload size of images:
+                * limit of Friendica ('maximagesize') or upload_max_filesize
+                * and outputs the lower one.
+               */
+               // init output var in case no number value could be retrieved.
+               $maximagesize_Mbytes = 0;
+               $dom_limitedby = '';
+               {
+                       // Get the relevant size limits for uploads. Abbreviated var names: MaxImageSize -> mis; upload_max_filesize -> umf
+                       $mis_bytes = DI::config()->get('system', 'maximagesize');
+                       // get_cfg_var('upload_max_filesize') outputs a string in the shorthand notation, need to convert it to bytes
+                       $umf_string = get_cfg_var('upload_max_filesize');
+                       $umf_bytes = filter_var($umf_string, FILTER_SANITIZE_NUMBER_INT);
+                       switch (substr($umf_string, -1)) {
+                               // According to https://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes only K, M, and G is used.
+                               case 'M':
+                                       $umf_bytes *= 10**6;
+                                       break;
+                               case 'K':
+                                       $umf_bytes *= 10**3;
+                                       break;
+                               case 'G':
+                                       $umf_bytes *= 10**9;
+                                       break;
+                       }
+                       if (is_numeric($mis_bytes) && is_numeric($umf_bytes)) {
+                               // When PHP is configured with upload_max_filesize less than maximagesize provide this lower limit.
+                               if ($umf_bytes < $mis_bytes) {
+                                       $maximagesize_Mbytes = ($umf_bytes / (10 ** 6));
+                                       $dom_limitedby = 'PHP.ini';
+                               } else {
+                                       $maximagesize_Mbytes = ($mis_bytes / (10 ** 6));
+
+                               }
+                       }
+               }
                $usage_message = DI::l10n()->t('The maximum accepted image size is %.3g MB', $maximagesize_Mbytes);
+               // Do we want to bother the end user with this information? If yes uncomment
+               // if (strlen($dom_limitedby) > 0) {
+               //      $usage_message .= ' ('. $dom_limitedby . ')';
+               // }
 
                $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');