Top Posts
- Preview of an image before it is uploaded
- Rails 3 - AuthLogic implementation - A basic tutorial
- Understand Rails Authenticity Token!
- Apache Thrift with Ruby - A basic Tutorial
- Remove a remote Git branch and tags
- Google Chrome Now on Linux
- Ruby-LDAP (add, search)
- Making beautiful graphs with Ruby
- New source path for ruby gems
Top Rated
Categories
- Git (2)
- Programming (7)
- Rails (8)
- ROR (7)
- Ruby (7)
- Thrift (1)
- Uncategorized (3)
Search with in my blog
Join 9 other subscribers
Hello,
I can see that there is a bug in your code. When I upload a file, the image does not preview immediately. Preview happens after uploading new file.
okay, i have already fixed the bug. In my case, I just replaced “input.files && input.files[0]” in the condition with the current value of the file field. It worked. ^^,
@pchan_august – Cool
I don’t know why it’s not working. Itried to understand what pchan_august said, but after thousand changes, nothing happens!
Hello ,
This is not working in IE.Can you please suggest me tha how it will work in iE ?
Thanks in advance
Hey cool,
I was searching for this functionality. Thanks for the Post.
I encounter lots and lots of this kind of sample. But not working in IE. Any suggestion?????
This is not working in IE.Can you please suggest me tha how it will work in iE ?
This is not working in IE.Can you please suggest me tha how it will work in iE ? other wise it is useless
Test
function showPreview(ele)
{
$(‘#imgAvatar’).attr(‘src’, ele.value); // for IE
if (ele.files && ele.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(‘#imgAvatar’).attr(‘src’, e.target.result);
}
reader.readAsDataURL(ele.files[0]);
}
}
Try just
<!–
–>
Test use this script in form and input type file, name filUpload,id filUpload onchang showPreview(this) and img id is imgAvatar
function showPreview(ele)
{
$(‘#imgAvatar’).attr(‘src’, ele.value); // for IE
if (ele.files && ele.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(‘#imgAvatar’).attr(‘src’, e.target.result);
}
reader.readAsDataURL(ele.files[0]);
}
}
<!–
–>
add js http://code.jquery.com/jquery-latest.js
Thanks dear …………. it works
its not working form mo on IE please help me out
i tried ur example its working ,thanks
Hi am try this what m search it that . a bug in IE its not work so any one solve this
please help.
thanks in advance
doesn’t work in safari 5.x.x how i could i use this for safari browser………???
it’s not working on IE !! anyone solved that??
Hi there,
You just saved my day.
I paste here the code of unobtrusive javascript, that everybode loves 😀
$(document).ready(function(){
$(“#fileFieldId”).change(function(){
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(‘#img_prev’).attr(‘src’, e.target.result).width(150).height(200);
};
reader.readAsDataURL(this.files[0]);
}
});
});
You just have to put the id of your file field and it will work as a charm. (Don’t forget the div which contains the image to preview :P)
thanks 😀
Thank you. Its working in Chrome and FireFox, but not in Safari.. Please help me to fix it?
Thank you
Pingback: Cakephp | Membuat Thumbnail Image (Upload File) dengan Js ImgAreaSelect
hi……..It’s working…
Hi
Thanks for your post it’s really helps me.but i need the image path too but it returns c:\fakepath\
like this image src value by javacript
thanku so.. much
Pingback: Before save Image preview on upload | Learning with Earning
this is working code………thanks.
hello there are multi preview sample ?
Ya its working
I can see that there is a bug in your code. When I upload a file, the image does not preview immediately. Preview happens after uploading new file. You have solved it pchan_august. Please post the code after bug fixing. Please…
It’s working…thanks .
How do i let this fill in a rails form ?
I have a and i want it to preview the image. But i cant seem to implement it in this code.
Thanks a lot for this information…its working n my problem solved.
Thanks. It works perfectly.
Pingback: [RESOLVED]How to preview image before upload using jquery | ASP Questions & Answers
Pingback: [RESOLVED]How to preview image before upload using jquery | ASP Web Form Data Control
Pingback: [RESOLVED]How to preview image before upload using jquery | ASP.NET MVC
Hello to every one, since I am in fact keen of reading this weblog’s post
to be updated regularly. It includes fastidious
material.
Thank you guys for your help
Nice Code, thank you !
Terima kasih from Indonesia
Pingback: Best way to show image previews before upload in rails & carrierwave