0

I wan to check the size of file at the time of upload in javascript (its an image file so if possible want to check in kb or bytes or in px)

Is there any way i can do it.

Thanks in advance!

<input type="file" name="ssimgfile2" id="ssimgfile2" />
user207888
  • 337
  • 2
  • 6
  • 19
  • possible duplicate of this http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation – theshadowmonkey Mar 27 '13 at 19:01
  • sorry i already searched but as i am not using HTML5 so window.FileReader,files[0] etc is not working for me...that's I posted here – user207888 Mar 27 '13 at 19:05
  • There is no other way to do it with JavaScript besides using the new features introduced as described here: http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation Thankfully, browsers are being updated more and more quickly, so it would actually be fairly safe to use that method. Just tell people not to use Internet Explorer. – Joseph Myers Mar 27 '13 at 19:16
  • Can't limit customer to not use IE so for now i will go with server side and may be later will think about it. Thanks for quick replies!! – user207888 Mar 27 '13 at 19:38

1 Answers1

1

JavaScript natively cannot find any information about a file other than the name. I know with Windows you can create a File System Object by defining a new ActiveX Object like so:

var myFSO = new ActiveXObject("Scripting.FileSystemObject");

I would advise using a Server Side scripting language like ASP, ColdFusion, or PHP depending on what type of web server you have.

Dion Pezzimenti
  • 243
  • 2
  • 11
  • I already used server side code in c# to check image size but as i was using multiple upload file so if it fails size limit for 1 file it ask to upload all files again...so wanted to check with javascript – user207888 Mar 27 '13 at 19:15
  • If you can do server-side code, then this is easy. Just check the header "Content-Length" which gives the entire size of all the uploaded data via POST form submission, including all image files together. It may be that some browser don't provided the content-length, but use chunked transfers for upload instead, but last I knew, those were rare. – Joseph Myers Mar 27 '13 at 19:18