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
Display upload file size limit on file upload form #6355
Comments
Seems fine. Display this in its own view/extension so site owners can easily remove it if they like. |
Few logistical questions:
|
The code for formatBytes is from php.net, licensed under CC license and AFAIK it's not compatible with MIT. I think we just need to write custom one. |
Do units like KB/MB need to be translated? |
@Srokap The formatBytes function I referenced is actually the second answer to that SO question (http://stackoverflow.com/a/2510540/1202510) I've modified it to return false to address the error if you pass 0 or a negative number, as well as using proper (I believe) standard symbols for kB, MB etc: function elgg_format_bytes($size, $precision = 2) {
if (!$size || $size < 0) {
return false;
}
$base = log($size) / log(1024);
$suffixes = array('B', 'kB', 'MB', 'GB', 'TB');
return round(pow(1024, $base - floor($base)), $precision) . ' ' . $suffixes[floor($base)];
} @mrclay I suppose it'd be more flexible to handle any file size unit to/from any other unit size, but that seems a bit beyond the scope of this feature. |
Already merged to 1.x, so closing. |
I've implemented this in a plugin, but I'm thinking this would be useful in the core files plugin.
It's easy enough to get the upload/post max sizes in bytes, ie:
The only missing piece of the puzzle is a function to convert bytes to a human
readable/friendly string. There's a ton of different ways to go about this..
I like this method (from: http://stackoverflow.com/questions/2510434/format-bytes-to-kilobytes-megabytes-gigabytes):
If anyone has a better solution for friendly byte formatting, please comment. I'll work this into a pull request otherwise..
The text was updated successfully, but these errors were encountered: