Source: http://www.ugia.cn /? P = 73
I have to admire this person's clever thoughts. I just got a few simple words!
Before a file is uploaded, the file type is determined by the file name. However, it is difficult to check the file size unless it is local or a control is used. However, IMG has several additional attributes in IE, such as: filecreateddate, filemodifieddate,Filesize, Fileupdateddate, filters. We can use these attributes to obtain part of the image file information, such as the file size. We use the file form in combination with the IMG tag, you can determine whether the image file size is valid before uploading. The following is a demo:
Restrictions:K
Another small discovery is that the onload event in the IE animation is triggered at the beginning of each loop, so that we can use it to achieve the same effect as the setinterval () function in JS, such:
Loops: 0
The source code of these two examples is as follows:
First:
Restriction: <input type = "text" size = "4" value = "10" name = "filesizelimit" id = "filesizelimit"/> K
<Input type = "file" name = "file1" id = "file1" size = "40" onchange = "changesrc (this)"/>
<SCRIPT type = "text/JavaScript">
VaR ofilechecker = Document. getelementbyid ("filechecker ");
Function changesrc (filepicker)
{
Ofilechecker. src = filepicker. value;
}
Ofilechecker. onreadystatechange = function ()
{
If (ofilechecker. readystate = "complete ")
{
Checksize ();
}
}
Function checksize ()
{
VaR Limit = Document. getelementbyid ("filesizelimit"). Value * 1024;
If (ofilechecker. filesize> limit)
{
Alert ("too large ");
}
Else
{
Alert ("OK ");
}
}
</SCRIPT>
Second:
loops: <span id = "loopsnum"> </span>
<SCRIPT type = "text/JavaScript">
VaR loops = 0;
Document. getelementbyid ("monkey"). onload = function ()
{
Document. getelementbyid ("loopsnum"). innertext = loops;
Loops ++;
}
</SCRIPT>
There are also some additional items in the manual:
<Input type = "hidden" name = "max_file_size" value = "30000"/>
Max_file_sizeThe hidden field (in bytes) must be prior to the input field, and its value is the maximum size of the received file. This is a suggestion for the browser. php will also check this item. This setting can be simply bypassed on the browser side, so do not expect this feature to block large files. In fact, the maximum value of uploaded files in PHP settings will not expire. However, it is best to add this project to the form, because it can avoid the trouble of File Upload failure only after the user spends the time waiting to upload a large file.
Note: The features discussed in this article are only valid in IE.