[jquery] 파일 업로드 전에 파일사이즈 체크하기
[upload.html]
<script>
$(document).ready(function() {
$("#flUpload").change(function () {
var iSize = 0;
if($.browser.msie){
var objFSO = new ActiveXObject("scripting.FileSystemObject");
var sPath = $("#flUpload")[0].value;
var objFile = objFSO.getFile(sPath);
var iSize = objFile.size;
iSize = iSize/ 1024;
}else {
iSize = ($("#flUpload")[0].files[0].size / 1024);
}
if (iSize / 1024 > 1) {
if (((iSize / 1024) / 1024) > 1) {
iSize = (Math.round(((iSize / 1024) / 1024) * 100) / 100);
$("#lblSize").html( iSize + "Gb");
}else{
iSize = (Math.round((iSize / 1024) * 100) / 100)
$("#lblSize").html( iSize + "Mb");
}
}else{
iSize = (Math.round(iSize * 100) / 100)
$("#lblSize").html( iSize + "kb");
}
});
});
</script>
<BODY>
Select file : <input type="file" id="flUpload" />
<br/><br/>
File Size is : <b><label id="lblSize" /></b>
</BODY>