In image upload,validate file dimenstions using javascript in IE 8 & IE 9

In image upload,validate file dimenstions using javascript in IE 8 & IE 9

What have you tried? What issues have you encountered while trying it?

2 Likes

We aren’t here to write it, for you. We are here to help you if you encounter issues while writing it, yourself.

Honestly, I’m not sure that it can be done in JavaScript. But, I’ve never really researched it.

V/r,

:slight_smile:

1 Like

Modern versions of JavaScript (not IE8 & 9) now have the ability to actually read a file from your visitor’s computer but I don’t know of any way to easily check the dimensions. Presumably you might be able to do it if you read the file content and work out what sort of image it is and then look at whereever that type of image stores the dimensions. You are out of luck with older browsers though as they have no way to access the image until after it has loaded onto the server.

That’s kind of what I thought. I would assume that kind of information would really be best done server-side. Upload it, check the dimensions, delete it if it doesn’t meet the criteria, move it if it does.

:slight_smile:

Or maybe resize it so it does meet the criteria.

But yes, AFAIK unless you use a Java Applet or ActiveX (which aren’t likely to be allowed) the image would need to be uploaded.

Hmmm, I’ve not heard of this before

I think felgall means this: https://developer.mozilla.org/en-US/docs/Web/API/FileReader

Yes. I haven’t actually tried that out yet but it is on my list to look at in more detail soon as I hope to add an example to my JavaScript site - since support for it is growing.

That looks like it has some potential. If MozDev is to believed it looks good enough to start trying now.

Browser compatibility
    Desktop

Feature 	Firefox (Gecko) 	Chrome 	Internet Explorer* 	Opera* 	Safari
Basic support 	3.6 (1.9.2) 		7 	10 			12.02 	6.0.2


    Mobile

Feature 	Firefox Mobile (Gecko) 	Android 	IE Mobile 	Opera Mobile 	Safari Mobile
Basic support 	32 			3 		10 		11.5 		6.1

You can’t trust the browser either - so validating from the server is a must.

Get the server checks done first as they’re more fundamental to the process, and only when the server-side of things is working should you come back to attempting it from the client-side browser.

3 Likes

Thanks for reply.

Actually i was looking a javascript code which will give me file dimensions. It should work in IE 8 & IE 9

To do that you are going to need to upload the file to the server first and then use an ajax call to server side functions to get the dimensions that can then be passed back to the browser. Those browsers don’t support any client side only processing that will even get you started on finding out the dimensions as they have no file access whatoever.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.