IE+JS: Check image file size before uploading
Detection before uploading a file usually determines whether the file type is legal by the file name, but it is difficult to detect the size of the file unless locally or using a control.
but under IE img has several additional attributes, such as: fileCreatedDate, fileModifiedDate, fileSize, fileUpdatedDate, filters, we can use these attributes to get some information about the image file, such as file size, we use the file form combined with the img tag, we will be able to determine whether the size of the picture file is legal before uploading.
Source code is as follows:
restriction:
& lt;input type="text" size="4" value="10" name="fileSizeLimit" id="fileSizeLimit"/> K& lt;input type="file" name="file1" id="file1" size="40" onchange="changeSrc (this) & quot;/>& lt;img src="https://www.chener.net/archives/101/about:blank" id="fileChecker" alt="test" height="18"/>& lt;script type="text/javascript">Var oFileChecker = document.getElementById (& quot;fileChecker")Function changeSrc (filePicker){OFileChecker.src = filePicker.value}OFileChecker.onreadystatechange = function (){If (oFileChecker.readyState = & quot;complete"){CheckSize ()}}Function checkSize (){Var limit = document.getElementById (& quot;fileSizeLimit"). Value * 1024If (oFileChecker.fileSize & gt; limit){Alert & quot;too large")}Else{Alert & quot;ok")}}& lt;/script>
--
from: UGIA.CN
Copyright Protection: ShuDudu from the original article, reproduced Please keep the link: https://www.shududu.com/life/IE-JS-Check-image-file-size-before-uploading.htm