Forum Moderators: open
I am very new to javascript and needs to restrict the size of image to be uploaded by using javascript to check the image's height and width against a spcified value before allowing it to be uploaded. Can somebody help me with the code that can help me achieve that.
Thanks in advance for your help.
needs to restrict the size of image to be uploaded by using javascript to check the image's height and width
I don't think this can be done. Think of it this way: the browser's file selection tool has no distinction as to what type of file it is. It could be a PDF file which has no inherent width and height. All the file upload object does is send the form data to the server, it doesn't actually read it.
You can't even read the local file for a file size, Javascript doesn't do that. If it could, that would be one truck-sized security hole. The only solution here, one used by most message boards, is to allow the upload to proceed and examine the file with a server-side program once it' fully uploaded. A typical example is to use perl and ImageMagick (or that "other" language, PHP :-) ) to examine the file's res, width, height, file type, and act accordingly. In most cases, it's just easier to resize it while processing rather than tell the user to do it, they may not even know how.
You'll have to dig in and start learning server-side programming or buy and install software to do this.