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
Show image size limit in Frio as "usagemessage" for photo_upload #12267
Conversation
forget to run |
Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
…filesize' is dominant for the actual image upload limit and print out the lower (relevant) one.
mod/photos.php
Outdated
// init output var in case no number value could be retrieved. | ||
$maximagesize_Mbytes = 0; | ||
$sizelimitedby = ''; | ||
{ |
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:
- Got the feeling this might be a little messy to be placed inline in
photos_contens.php
and should be moved to a function, e.g. to be reused in the Admin Site. - But until I am not sure where to put it best as a Function, I used the local block for hiding the wars to the rest of the function to emphasize that they are just used for the conversion and comparison.
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 :-)
mod/photos.php
Outdated
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Please use ini_get()
instead, it will return the computed value as an integer value or an integer string you can use directly.
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.
At least not on my setup
gettype(ini_get('upload_max_filesize')): String
ini_get('upload_max_filesize'): 20M
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.
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 src/Util/Strings.php
file with the signature public static function getBytesFromShorthand(string $val): int
and then you can refer to it in mod/photos.php
as Strings::getBytesFromShorthand()
.
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.
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 10**x
.
When it is about binary prefixes, shouldn't we use KiB, MiB, Gib?
But for the moment: Which interpretation of k, M, G is used in this project: 10**x
(si / deicmal) or 2**x
(binary). I never be sure in the k, M, G cases, only when binary prexies are used it is celar for me that they relate to 2**x
:-)
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.
The PHP manual you linked to earlier mentions the shorthands are meant to be binary prefixes.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
… cluclate 2**20 for just deviding the bytes by one constant divisor.
… calculate 2**20 for just dividing the bytes by one constant divisor.
# Conflicts: # src/Util/Strings.php # view/lang/C/messages.po
While wrapping
Should we not convert a |
…) with Strings::getBytesFromShorthand()
I've never used infinity, but feel free to do so if tests are successful. |
Already started it, should not be a problem as long as we have INF only in the numerators. |
For me, at the moment anything is done besides a general discussion about how we handle limit of -1 and 0 in general, but I created a new issue for that. This PR now should behave as defined with 0 meaning actually no limited and any size is accepted where ever the image size is evaluated. |
There still seams to be a problem with |
Fixed it. But there is this method Will suggest a handling for INF in the next commit. |
Should all be fixed, upload now works for profile pics. Main Upload still broken due to another issue not addressed here |
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.
I'm not convinced by the use of INF
, we were already checking whether maximagesize
had a value or not, which is the same condition as replacing its value by INF
.
|
||
if ($maximagesize == 0) { | ||
$maximagesize = INF; | ||
} | ||
|
||
if ($maximagesize && ($filesize > $maximagesize)) { |
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.
This condition was already effectively using 0
to disable the check, not sure using INF
here adds anything.
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.
That is the point, if we pass maximagesize == 0
to line 663, the processing will be discarded and since fileesize
will always > 0
. And this is contradicting the semantic that maximagesize == 0
should effect "no limit"
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.
Ahh sorry, now I get it (as you already guessed I am not too familiar with PHP ;-) ) since the AND condition is already false because PHP trades "0" as false. I get it. You are right, then it is not necessary.
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.
There are two variants of this if statement in line 663, the other one is !isempty($maxfilesize)
. I will adjust it by removing isempty()
.
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.
Thanks, it bothered me too but I didn't want to pile on you.
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.
One last change!
Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
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.
Thank you for your work!
As a first step on no image size limit shown on upload site issue , the configured limit is now printed in the already existing but previously empty
usageinfo
in the frio template forphotos_upload.tp
The value of maximagesize in bytes is converted to MB before printing.
Please comment this request regarding code quality and practice.