How to resolve the C:\fakepath?

后端 未结 13 1740
梦如初夏
梦如初夏 2020-11-21 13:34

This is my upload button.



        
13条回答
  •  我寻月下人不归
    2020-11-21 14:05

    Use file readers:

    $(document).ready(function() {
            $("#input-file").change(function() {
                var length = this.files.length;
                if (!length) {
                    return false;
                }
                useImage(this);
            });
        });
    
        // Creating the function
        function useImage(img) {
            var file = img.files[0];
            var imagefile = file.type;
            var match = ["image/jpeg", "image/png", "image/jpg"];
            if (!((imagefile == match[0]) || (imagefile == match[1]) || (imagefile == match[2]))) {
                alert("Invalid File Extension");
            } else {
                var reader = new FileReader();
                reader.onload = imageIsLoaded;
                reader.readAsDataURL(img.files[0]);
            }
    
            function imageIsLoaded(e) {
                $('div.withBckImage').css({ 'background-image': "url(" + e.target.result + ")" });
    
            }
        }
    

提交回复
热议问题