1.jsp page Code
[HTML]View PlainCopy
- <form id=" Userphoto " name=" Userphoto " method= "post" action=enctype=" Multipart/form-data " span class= "tag" >>
- <input Type= "hidden" id= "Max _photosize " name=" maxphotosize " value= "${maxphotosize}" />
- <input type="hidden" id="Phototype" name= "Phototype" value= ""/>
- <input type="file" id= "filephoto" value= ""
- style="Font-size:400px;opacity:0;filter:alpha (opacity:0);-moz-opacity:0;position:absolute;top:0px;left : 0px;width:400px;height:400px;z-index:100;overflow:hidden;cursor:pointer; "
- name="Userphoto"/>
- < Img style= "top:0px;left:0px;z-index:99" id= "Imguserphoto" src= " width=" height= ">&NBSP;&NBSP;
- <table cellpadding="0" cellspacing= "0" width="100%" height= "100% " border="0" align= "Center">
- <tr>
- <TD Width="100%" align= "Center" valign="Middle">
- <s:hidden id="userId" name="User.userid" />
- </td>
- </tr>
- </Table>
- </form>
2.js Code
[JavaScript]View PlainCopy
- function Uploadimage () {
- var fileSize = 1024 * 5000;
- var maxfilesize= $ ("#max_PhotoSize") [0].value;
- var location = $ ("#filePhoto") [0].value;
- var point = Location.lastindexof (".");
- var type = LOCATION.SUBSTR (point);
- $ ("#photoType"). val (type);
- if (type = = ". jpg" | | type = = ". gif" | | type = = ". JPG "| | Type = = ". GIF "| | Type = = ". bmp" | | type = = ". BMP "
- || Type = = ". jpeg" | | type = = ". JPEG "| | Type = = ". PNG "| | Type = = ". png") {
- if ($.browser.msie) {//ie
- var img = document.createelement ("img");
- IMG.SRC = $ ("#filePhoto") [0].value;
- FileSize = img.filesize;
- }
- if ($.browser.mozilla | | (Navigator.userAgent.toLowerCase (). Match (/chrome/) =null)) {//Firefox or Chrome
- FileSize = $ ("#filePhoto") [0].files[0].size;
- }
- if (FileSize > maxfilesize*1024) {
- Alert ("picture size please do not exceed" +maxfilesize+ "KB");
- return false;
- } Else {
- $ ("#userPhoto") [0].submit ();
- return true;
- }
- } Else {
- Alert ("upload images in jpg,gif,bmp,jpeg,png format only");
- return false;
- }
- return true;
- }
3. Supplement:
The above about the verification of IE, suitable for the previous version of IE6, for IE7 version of the foreground is not good to judge the size of the picture, it is best to judge by the background:
(1) Submit the form first
(2) in the background to determine the size of the submission picture file, if it is greater than the maximum limit, do not do any processing, return the prompt, if within the maximum limit, then save and other processing
Using input to upload images, to determine the different browser and image type and size of the JS code