1

Is there is any method for validating the dimensions of the image file before uploading to the server ..

In details

I had a PHP file upload form and image upload will restrict with specific dimensions . Already I am checking in server side and also I wanna check the image dimensions before uploading process

Please help Thanks

ramesh
  • 4,008
  • 13
  • 72
  • 117
  • 2
    I've only seen it done with flash / silverlight / exe / applet, never seen it with pure html yet, similar question asked here: http://stackoverflow.com/questions/8486414/check-image-dimensions-height-and-width-before-uploading-image-using-php – ToddBFisher Jan 30 '12 at 06:14
  • until it is uploaded php has nothing to check. –  Jan 30 '12 at 06:24

2 Answers2

2

Yes, it's possible. pupload for example can resize images on the client side.

Take a look at the HTML5 runtime source to see how it determines the dimensions.

konsolenfreddy
  • 9,551
  • 1
  • 25
  • 36
  • PLupload rocks! +1, Side note: "Image resizing is only possible on Firefox 3.5+ (with fixed quality) acnd Chrome. Safari/Opera doesn't support direct data access to the selected files." - http://www.plupload.com/ – ToddBFisher Jan 30 '12 at 06:29
1

Check this example http://jsfiddle.net/WQNzY/1/ I've created based on this great MDN tutorial

It make use of FileReader API, so you would like to check what browsers support it currently. Now it works in Mozilla, Chrome, Opera. But sure for old browsers you need anyway use server side validation. Not a big deal because you anyway need it alongside with client-side but for modern browsers you could make user experience more smooth and pleasent.

dfsq
  • 191,768
  • 25
  • 236
  • 258