<html>
<head>
<title>test</title>
<script language="JavaScript">
function importPrompt()
{
var tipMsg = "browser version too low, suggest you to upgrade or try other browsers!";
var errMsg = "import file size is greater than 250kb!";
if (!window.FileReader)
{
alert(tipMsg);
return false;
}
var oFile = document.getElementById("fileupload").files[0]; // input box with type file;
var img = document.getElementById("imgtag");
var fileSize = 0;
var maxsize = 250*1024;//250kb
var reader = new FileReader();
reader.onload = function (e)
{
console.log(e.total); // file size
img.src = e.target.result; // putting file in dom without server upload.
};
reader.readAsDataURL(oFile );
fileSize = oFile.size;
if(fileSize>maxsize)
{
alert(errMsg);
return false;
}
else
{
return confirm("select yes to upload");
}
}
</script>
</head>
<body>
<img id="imgtag" dynsrc="" src="" style="display:none" />
<form action=‘#‘ onsubmit="return importPrompt();">
<input type="file" name="ImportFile" id="fileupload" >
<input type="submit" id="button" value="restor">
</form>
</body>
</html>