, what I want to do when the user selects a fi...">

Html how to link to file in input tag

Suppose I have a simple form with a tag <input type="file">, what I want to do when the user selects a file, I would like to display this file (this is img) on ​​the same page for viewing, the best user interface.

tried to set the value based on the onChange event, and then realized that this was not working.

any thoughts?

+3
source share
3 answers

You cannot access the client file system from an isolated browser program. This is contrary to the browser security model. You just need to wait for the user to upload the file before you can display it.

+3
source

- onChange Ajax ().

: onChange script.

-, , , . !

+1

You do not need to upload an image before you can display it. Here is a jQuery snippet that will fit the trick:

$('input:file').change(function(){
    var file = this.files[0];  
    var reader = new FileReader();  
    reader.onload = (function(event) { 
    $('#previewImage').attr('src',event.target.result); 
    });  
    reader.readAsDataURL(file);   
});
0
source

All Articles