hoangweb
7/12/2018 - 12:09 AM

js - display image when select input file html

display image when select input file html

<input type='file' onchange="readURL(this);" />
    <img id="blah" src="#" alt="your image" />

<script>
function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah')
                .attr('src', e.target.result)
                .width(150)
                .height(200);
        };

        reader.readAsDataURL(input.files[0]);
    }
}
</script>