How to resolve the C:\fakepath?

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

This is my upload button.



        
13条回答
  •  感情败类
    2020-11-21 13:55

    I use the object FileReader on the input onchange event for your input file type! This example uses the readAsDataURL function and for that reason you should have an tag. The FileReader object also has readAsBinaryString to get the binary data, which can later be used to create the same file on your server

    Example:

    var input = document.getElementById("inputFile");
    var fReader = new FileReader();
    fReader.readAsDataURL(input.files[0]);
    fReader.onloadend = function(event){
        var img = document.getElementById("yourImgTag");
        img.src = event.target.result;
    }
    

提交回复
热议问题