Javascriptは画像のサイズを取得します.
1907 ワード
<%= form_tag '/blogs/upphoto', :id => "upform", :multipart => true, :target => "showupimg", :onsubmit => "return uploadcheck();" %>
<span style="margin-left:30px;"></span>
<input class="imgfile" name="imgfile" type="file" size="40"/>
<input class="upbutton" name="upload" type="submit" value=" " />
</form>
// form
function uploadcheck(){
//
var upform = document.getElementById('upform');
var imgstring = document.getElementById('upform').imgfile.value;
if (imgstring == ''){ // ?
alert(" ");
return false;
}
imgtype = imgstring.substring(imgstring.lastIndexOf(".")+1, imgstring.length).toLowerCase();
alert(imgtype);
//
if (imgtype != "gif" && imgtype != "jpg" && imgtype != "jpeg" && imgtype != "png" && imgtype != "bmp"){
alert( " , JPEG.JPG.GIF.PNG.BMP ! " )
return false ;
}
//
var img = new Image();
var MAXSIZE = 1000;
alert(imgstring);
img.src = imgstring;
alert(img.fileSize);
if (img.fileSize > MAXSIZE*1024) {
alert( " 1M " );
return false ;
}
var img_count = document.getElementById("showimgs").getElementsByTagName("img").length;
if (img_count >= 15) {
alert(" 15 , , , , !");
return false;
}
}
img.fileSize 。