I would like to do below validations for single file uploaded using jQuery Uploadify plugin.
- Check for the file type .jpg, .png & .gif
- Check for the file size maximum 2MB only
I have done this through fileExt & sizeLimit options, but as the plugin developer says, one can easily bypass the fileExt validation & server side validation is recommended.
I want to do this using PHP server side scripting language.
I have already checked the documentation of the plugin & nothing helpful found there.
Can someone please suggest how to do this ?
Thanks in advance.
I would recommend using the filesize and exif_imagetype functions to assess the file. The following should point you in the right direction:
Note that the
filesize()function in PHP returns the size in bytes, thus, the file should be less than$two_mbbytes. Also, theexif_imagetype()returns an integer code mapping to the MIME type of the uploaded image: 1, 2, 3, being.gif,.jpg, and.pngrespectively.