1

I m trying to display image after selecting it directly on the onchange event of an input file i figure it out how it done in all browsers but i stopped by safari i m trying to get the

inputFile.value property but it returns me a fake path i neeeeeeeed help even with a walk around that issue but i don't need a post back.

Regards

Marwan
  • 2,362
  • 1
  • 20
  • 35
  • So you're asking us to correct your code without showing it? – Tim Schmelter Oct 20 '12 at 23:51
  • no its not like that all am asking is a solution for a fakepath returns i make up a search every where but i found nothing – Marwan Oct 20 '12 at 23:54
  • I wonder why you're getting only in Safari a fake path since even IE returns only the file-name since version 7. http://rattomago.wordpress.com/2009/02/18/accessing-filepath-in-html-input-element-via-javascript/ Is it an intranet or internet application? – Tim Schmelter Oct 20 '12 at 23:55
  • in IE 8 yes but in 9 i find the full path is a simple internet app – Marwan Oct 20 '12 at 23:58
  • http://stackoverflow.com/questions/268889/retrieving-the-full-path-server-side-of-a-file-uploaded-using-firefox – Reflective Oct 21 '12 at 00:02
  • I Sow a jquery plugin did it but i dont know is it working around i will find it and comeback to discuss – Marwan Oct 21 '12 at 00:15
  • http://stackoverflow.com/questions/527955/how-can-i-upload-a-file-using-javascript-without-a-postback Guys see this link jquery do it i with to know how to do it in pure javascript – Marwan Oct 21 '12 at 08:07

1 Answers1

0

Suppose your input and image are as under

<img id="PreviewImage" src="" alt="?" style="height:100px;"  />
<input id="ImageFileUpload" onchange="readURL(this);" type="file" runat="server"/>

function readURL(input) {
if (input.files && input.files[0]) {//Check if input has files.
var reader = new FileReader(); //Initialize FileReader.

reader.onload = function (e) {
$('#PreviewImage').attr('src', e.target.result);
$("#PreviewImage").resizable({ aspectRatio: true, maxHeight: 300 });
};
reader.readAsDataURL(input.files[0]);
} 
else {
$('#PreviewImage').attr('src', "#");
}
}
Abdul Majid
  • 95
  • 1
  • 10
  • may be works in some browsers but not in every FileReader is not compatable with all browsers – Marwan Oct 21 '12 at 08:07