Preview image before uploading in IE9

I want to display an image before uploading. I tried the following code, but it only works in firefox.but, I need to get it to work in IE. Can anyone suggest me a better solution for this. I give my code below can someone figure out where I went I googled almost one whole day. But could not find my solution. Here is my code.

enter code here function loadname(img, previewName) { var isIE = (navigator.appName == "Microsoft Internet Explorer"); var path = img.value; var ext = path.substring(path.lastIndexOf('.') + 1).toLowerCase(); if (ext == "gif" || ext == "jpeg" || ext == "jpg" || ext == "png") { if (isIE) { alert(path); $('#' + previewName).attr('src', path); } else { if (img.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#' + previewName).attr('src', e.target.result); } reader.readAsDataURL(img.files[0]); } } } } 

My html

  <body><form method="post" > <input type="file" class="file" onchange="loadname(this,'previewimg')" id="file" /><img src="about:blank" name="previewimg" id="previewimg" alt="" style="width:2in; height:2in"/> </form> 
+6
source share
1 answer

For security reasons, IE9 does not support access to files on the client computer, so you do not see any preview. You will need to upload the image to your server and then display it.

VIEWING BIRDS

One way might be that when loading, a progress bar is shown when using ajax to save the file to a temporary folder on your server with the image name as a temporary identifier and saving the identifier in the database (so you can delete it later), and then display it in the image control. If you need to delete the file later, simply delete it using the identifier, or if you need to save it, move it to the image folder.

+6
source

Source: https://habr.com/ru/post/919374/


All Articles