-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show image size limit in Frio as "usagemessage" for photo_upload #12267
Changes from 6 commits
d402fe3
c11e2b0
9dd1cf8
bb67f6e
74bab60
c4c1bd2
907deed
f4d49e5
f88722b
6c73077
ce56cab
765b50b
54289b2
597f1ba
f45b358
719c294
a01872a
6ebf0f8
6877f8a
5b2ac7b
d43e393
361908c
bfe220c
77c68d1
3cf0b9b
25ba8bf
10e0672
e73451d
9c383e2
d44968c
c03784e
978fe26
b2f962c
7d86cb1
72b3bbb
0ea219f
49db646
2794100
99e1c64
bbd1c34
ca7af7a
97a3587
bb9afc5
037e181
75b01f6
a3d8a59
0080832
79235b6
f9c0d5a
e4fd9d4
8f5d6fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -914,7 +914,47 @@ function photos_content(App $a) | |
'$submit' => DI::l10n()->t('Submit'), | ||
]); | ||
|
||
$usage_message = ''; | ||
/* 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; | ||
$sizelimitedby = ''; | ||
{ | ||
// 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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least not on my setup
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gasp! Never mind then, here's a conversion function you should use (notice the 1024 factor instead of the 1000 you've been using): https://stackoverflow.com/a/6846537 You can declare it in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I will do so shortly. Already thought about the binary / si prefix issue myself, which is also related to the issue: Whenever I encounter a si prefix (kB, MB, ...) I assume it is decimal prefix But for the moment: Which interpretation of k, M, G is used in this project: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PHP manual you linked to earlier mentions the shorthands are meant to be binary prefixes.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
$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)); | ||
$sizelimitedby = '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($sizelimitedby) > 0) { | ||
// $usage_message .= ' ('. $sizelimitedby . ')'; | ||
//} | ||
|
||
$tpl = Renderer::getMarkupTemplate('photos_upload.tpl'); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this curly bracket block for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons:
photos_contens.php
and should be moved to a function, e.g. to be reused in the Admin Site.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the curly brackets can be removed at will, no problem at all :-)