Reputation: 293
I have this code to get the size of an uploaded file:
var iSize = ($("#formmedia")[0].files[0].size / 1024);
if (iSize / 1024 > 1)
{
if (((iSize / 1024) / 1024) > 1)
{
iSize = (Math.round(((iSize / 1024) / 1024) * 100) / 100);
$("#size").html( iSize + "Gb");
}
else
{
iSize = (Math.round((iSize / 1024) * 100) / 100)
$("#size").html( iSize + "Mb");
}
}
else
{
iSize = (Math.round(iSize * 100) / 100)
$("#size").html( iSize + "kb");
}
This code works completely fine but it shows the output as:
<div id="size">5.78 Mb</div>
How can I get it to ALWAYS ONLY show Kilobytes?
Upvotes: 1
Views: 6882
Reputation: 1010
Simply remove all but:
var iSize = ($("#formmedia")[0].files[0].size / 1024);
iSize = (Math.round(iSize * 100) / 100)
$("#size").html( iSize + "kb");
So that the size is simply converted to kb regardless of how large the file is.
Upvotes: 1
Reputation: 960
Just remove the parts that check if its >1MB or >1GB, and you're left with:
var iSize = ($("#formmedia")[0].files[0].size / 1024);
iSize = (Math.round(iSize * 100) / 100)
$("#size").html( iSize + "kb");
Upvotes: 5