I am using Asp.Net MVC and Jquery. I have a form which contains file input control to upload Image .I want to preview the selected image before saving into database.
The code I used is here.
<img id="preview_image" alt="" src="" width="100px" height="120px"/>
<input type="file" name="user_image" id="user_image" onchange="preview(this);"/>
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
function preview(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#preview_image')
.attr('src', e.target.result)
.width(100)
.height(120);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
It is not working in Internet Explorer and Safari. Because 'FileReader' is not supported in these browsers
Is there any other solution without using any Flash plugin? Thanks in advance