Determining the size of the file using JavaScript and HTML5.

Posted by Vishalneeraj-24503 under HTML 5 category on | Points: 40 | Views : 850
HTML5 allows developers to access the file contents and details using JavaScript and jQuery and hence in browsers that support HTML5 one can easily determine the size of the File.
Inside this function, first a check is performed to verify whether the browser supports HTML5 File API. If the browser supports HTML5 File API then the size of the file is determined and the displayed.
<input type="file" id="fileUpload" />
<input type="button" value="Upload" onclick="Upload()" />
<script type="text/javascript">
function Upload() {
var fileUpload = document.getElementById("fileUpload");
if (typeof (fileUpload.files) != "undefined") {
var size = parseFloat(fileUpload.files[0].size / 1024).toFixed(2);
alert(size + " KB.");
} else {
alert("This browser does not support HTML5.");

Comments or Responses

Login to post response