Check image width and height before upload with Javascript

前端 未结 8 755
情歌与酒
情歌与酒 2020-11-22 14:53

I have a JPS with a form in which a user can put an image:

Photo (max 240x240 and 100 kb):
8条回答
  •  逝去的感伤
    2020-11-22 15:41

    function uploadfile(ctrl) {
        var validate = validateimg(ctrl);
    
        if (validate) {
            if (window.FormData !== undefined) {
                ShowLoading();
                var fileUpload = $(ctrl).get(0);
                var files = fileUpload.files;
    
    
                var fileData = new FormData();
    
    
                for (var i = 0; i < files.length; i++) {
                    fileData.append(files[i].name, files[i]);
                }
    
    
                fileData.append('username', 'Wishes');
    
                $.ajax({
                    url: 'UploadWishesFiles',
                    type: "POST",
                    contentType: false,
                    processData: false,
                    data: fileData,
                    success: function(result) {
                        var id = $(ctrl).attr('id');
                        $('#' + id.replace('txt', 'hdn')).val(result);
    
                        $('#imgPictureEn').attr('src', '../Data/Wishes/' + result).show();
    
                        HideLoading();
                    },
                    error: function(err) {
                        alert(err.statusText);
                        HideLoading();
                    }
                });
            } else {
                alert("FormData is not supported.");
            }
    
        }
    

提交回复
热议问题