<form name="upload" action="">
<input type="file" name="fUpload" id="fUpload" onchange="GetFileSize('fUpload')" />
<input type="button" value="Get File Size" onclick="GetFileSize('fUpload');" />
</form>
<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript" > </script>
<script type="text/javascript">
function GetFileSize(fileid) {
try {
var fileSize = 0;
//for IE
if ($.browser.msie) {
//before making an object of ActiveXObject,
//please make sure ActiveX is enabled in your IE browser
var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var filePath = $("#" + fileid)[0].value;
var objFile = objFSO.getFile(filePath);
var fileSize = objFile.size; //size in kb
fileSize = fileSize / 1048576; //size in mb
}
//for FF, Safari, Opeara and Others
else {
fileSize = $("#" + fileid)[0].files[0].size //size in kb
fileSize = fileSize / 1048576; //size in mb
}
alert("Uploaded File Size is " + fileSize + "MB");
}
catch (e) {
alert("Error is :" + e);
}
}
</script>
<input type="file" name="fUpload" id="fUpload" onchange="GetFileSize('fUpload')" />
<input type="button" value="Get File Size" onclick="GetFileSize('fUpload');" />
</form>
<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript" > </script>
<script type="text/javascript">
function GetFileSize(fileid) {
try {
var fileSize = 0;
//for IE
if ($.browser.msie) {
//before making an object of ActiveXObject,
//please make sure ActiveX is enabled in your IE browser
var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var filePath = $("#" + fileid)[0].value;
var objFile = objFSO.getFile(filePath);
var fileSize = objFile.size; //size in kb
fileSize = fileSize / 1048576; //size in mb
}
//for FF, Safari, Opeara and Others
else {
fileSize = $("#" + fileid)[0].files[0].size //size in kb
fileSize = fileSize / 1048576; //size in mb
}
alert("Uploaded File Size is " + fileSize + "MB");
}
catch (e) {
alert("Error is :" + e);
}
}
</script>
0 comments:
Post a Comment