Put this code between <head>...</head> tag.
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#test').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
Put this code in main body.
<form id="form1" runat="server">
<input onchange="readURL(this);" type="file" />
<img alt="Image Display Here" id="test" src="#" />
</form>
Enjoy :
Holy crap, this is short, simple and actually works! Thanks so much for posting.
ReplyDeleteIs there any residual data saved somewhere each time an upload takes place? Does something have to be reset, deleted, or cleared somehow?
thanks for this good one script
ReplyDeleteits de best
ReplyDeleteThanks! This is a perfect solution!
ReplyDeleteyou are the best !
ReplyDeletethanks dear ....
ReplyDeletefantastic..!!! this was very usefull...!!!! thanks a ton dude..!!!
ReplyDeleteThis rily cool. does anyone know how to resize the preview image?
ReplyDeleteThanks, this is really very useful....!!!
ReplyDeleteThanks, really a good stuff.., but its not working with IE8 any help Appreciated..!!
ReplyDeleteIts working good in Firefox and Chrome but not in IE browser
ReplyDeletethnx Dear
ReplyDeleteNot display image preview, please help...
ReplyDeletePlease write error here, I help you to solved that.
Deletesame problem Not display image preview
ReplyDeletePlease write error here, I help you to solved that
Deletethanks for help.
ReplyDeleteit doesn't show jpg images :P, ithink it cant be done widout ajax after all
ReplyDeleteThanks bro
ReplyDeletei upload multi file but show 1 file.u can help me , please ?
ReplyDeleteThanks a lot. May GOD bless you!
ReplyDeletePawan chouhan
Awesome dude! May God bless you :)
ReplyDeleteThank You!
DeletePicture not displaying
ReplyDeletePlease write error here, I help you to solved that.
DeleteThanks a lot. Its working fine!
ReplyDeleteThanks To All!
ReplyDeleteThankyou for your post, but not showing image and not showing any error, only showing "alt" text
ReplyDeleteFor this to work add above script basic jquery file needs for its working in script tag and or add following in script tag src attribute
ReplyDeletesrc="//code.jquery.com/jquery-1.10.2.js"
its not working in local
ReplyDelete@Ashish
Deletecan you please explain exact error which generated in your local server, So I help you to solve that.
Enjoy!
Nice Code
ReplyDeleteThanks... it helped a lot.
ReplyDeleteHi, did not work for me. Probably because the runat="server" script requires asp.net, which I don't understand what it means. I'm working with normal php files, nothing special. Help please?
ReplyDeleteCan you try with remove runat="server" from 'form' tag?
DeleteIf any issue there after removing then tell me :)
Amazing man, thanks
ReplyDeletethanks so much but how do i go about it now that am uploading multiple images at once please....waiting please
ReplyDeleteVery Helpful! Thank you!
ReplyDeletethank you
ReplyDeletemy it wont display image?
ReplyDelete@Ness: Please send me your exact problem when upload any image? So I try to help you to solve that.
DeleteThanks.
i want to upload two image at same form how can i apply this logic ?
Deletemultiple images, multiple previews, id love to know too
Deletethanks ...it works..but it doesnt if i use for multiple img,, can help?
ReplyDeletedamn thanks alot it's work
ReplyDeletethis is great man! thanks for this/
ReplyDeleteI'm testing this on Chrome, and it doesnt work.
ReplyDeleteAll it shows it's a broken image before and after I select the image.
I'm testing on a blank new page with the exact code showing here. Any clues?
but sir it is only one input valid
ReplyDeletebut i use four input and different different image upload but image is not show preview
This will not work for me. It only shows the image alt text
ReplyDeleteOH! you are a life saver! thanks a lot dude
ReplyDeleteWoooh, this script worked for me, thanks a lot
ReplyDeleteI found the perfect solution.
ReplyDeleteImage preview before upload