Reputation: 2564
function upload_img(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#preview_image').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
<input type="file" id="image" onchange="upload_img(this);"/>
<img id="preview_image">
I have a function can preview the image from user upload without submit.
it works fine in all browser but safari, anyone know where is the problems?
Upvotes: 1
Views: 344
Reputation: 428
check this
if(window.FileReader) { //do this
} else {
//the browser doesn't support the FileReader Object, so do this
}
Upvotes: 1