0

i found this code on online its checking only file types, How to add file height and file wight and also file size to this jquery function i found this code on online its checking only file types, How to add file height and file wight and also file size to this jquery function

(function($) {
    $.fn.checkFileType = function(options) {
        var defaults = {
            allowedExtensions: [],
            success: function() {},
            error: function() {}
        };
        options = $.extend(defaults, options);

        return this.each(function() {

            $(this).on('change', function() {
                var value = $(this).val(),
                    file = value.toLowerCase(),
                    extension = file.substring(file.lastIndexOf('.') + 1);

                if ($.inArray(extension, options.allowedExtensions) == -1) {
                    options.error();
                    $(this).focus();
                } else {
                    options.success();

                }

            });

        });
    };
})(jQuery);

Calling

$(function() {
    $('#shop_logo').checkFileType({
        allowedExtensions: ['jpg', 'jpeg'],
        success: function() {
            alert('Success');
        },
        error: function() {
            alert('Only jpg images');
        }
    });
});
thefourtheye
  • 233,700
  • 52
  • 457
  • 497
SAGAR.G
  • 39
  • 6
  • Take a look [here for filesize](http://stackoverflow.com/questions/7497404/get-file-size-before-uploading), and [here for dimensions](http://stackoverflow.com/questions/13572129/is-it-possible-to-check-dimensions-of-image-before-uploading) – Michel Oct 18 '14 at 07:18
  • javascript only has access to the html on your page. Not to files. Maybe the html contains code like . Do you wish to extract data from there? Or how do you have access to the files in question? – PaulH Oct 18 '14 at 08:02
  • When uploading files, the basic functionality works through filenames. Checking extension is part of checking filename, that is easy. Checking image dimension is much more complex. Are you prepared for that complexity? – PaulH Oct 18 '14 at 08:11
  • For files size, do you need to support Internet Explorer 8 or 9 or Opera mini? See support overview at http://caniuse.com/#feat=fileapi – PaulH Oct 18 '14 at 08:17

0 Answers0