0

I want to check the image size in JavaScript.. for example if image size is more than 500kb and other format instead of jpg.. it should not get uploaded.. i want to check these validation before form submit..

thanks in advance..

waiting for positive ans.

Regards

3
Contributors
2
Replies
6
Views
5 Years
Discussion Span
Last Post by Troy III
0

A solution is offered HERE (see Rodboy's post part way down the page).

I have not tested the code but on first inspection it appears to be an honest offering. It is dated 2007 so may be no longer valid. Note the in-code comment to the effect that file size detection is not guaranteed, therefore javascript would only be a first line of defence; a server-side accept/reject check would also be necessary.

Airshow

0

I want to check the image size in JavaScript.. for example if image size is more than 500kb and other format instead of jpg.. it should not get uploaded.. i want to check these validation before form submit..

thanks in advance..

waiting for positive ans.

Regards

This will do your thing on all versions of Explorer.

<input type=file id=fileUp onchange="getImg()">
<img id=imgProbe src="" style="width:100px; display:block">
<script>
getImg=function(){
	imgProbe.src=fileUp.value;
	imgProbe.onload=function(){
		(imgProbe.fileSize/1024)>500?
		alert("500KB Exceeded!"):imgProbe.mimeType.match(/jpeg/i)?
		1:alert("JPG Required!")
		}
	}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.