-
New Feature
-
Resolution: Done
-
Normal
-
8.0.2
-
None
-
Security Level: Jimmy
-
None
-
ZK 8.0.3 S7, ZK 8.0.3 S9, ZK 8.0.3 S10, ZK 8.5.2 S1, ZK 8.5.2 S2
-
None
When exceeding max size, the Dropupload always displays a file size in KB. The code below can convert a file size to the most readable size unit:
<dropupload maxsize="5" detection="none" onUpload="" > <attribute name="content"><![CDATA[ <b>Drop Here</b><br/> size < 5k ]]></attribute> </dropupload>
zk.fmt.Text.stuff = zk.fmt.Text.format; /** * Formatting a filesize depending on its value: * >= 1024 GB: 0.0 TB, * >= 1024 MB: 0.0 GB, * >= 1024 KB: 0.0 MB, * >= 1024 B : 0.0 KB, * else: bytes. Decimal point is determined by System language. */ zk.fmt.Text.formatFileSize = function (bytes) { var divider = 1024; if(Math.abs(bytes) < divider) { return bytes + msgzk.BYTES; } var units = [msgzk.KBYTES, msgzk.MBYTES, msgzk.GBYTES, msgzk.TBYTES] var unit = -1; do { bytes /= divider; ++unit; } while(Math.abs(bytes) >= divider && unit < units.length - 1); return +bytes.toFixed(1) + ' ' + units[unit]; } zk.fmt.Text.format = function (msg) { if (msg == msgzul.UPLOAD_ERROR_EXCEED_MAXSIZE) return zk.fmt.Text.stuff(msg, zk.fmt.Text.formatFileSize(arguments[3]), zk.fmt.Text.formatFileSize(arguments[4])); else return zk.fmt.Text.stuff(arguments); }