I have modified the function
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#upload").change(function() {
readURL(this);
});
</script>
and included this input in my form in the body element:
<input type="file" name="uploaded_files" id="upload"/>
<img id="blah" src="#" alt="your image" />
I have also included jQuery:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
It’s working in JsFiddle, but it’s not working on my localhost.
There is absolutely nothing wrong with what you have done, neither with your script JS block. You can go and check on this JSFiddle.
Just make sure you are loading the jQuery library correctly since your script depends on.
Try Like
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
Demo
Related
I've looked other questions and found this code is working but it's not working. I've tried clearing cache in browser but still it's not working. Can anyone tell me what is wrong?
<script>
function showImage(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#pic').attr('src',e.target.result).width(200).height(200);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
HTML code
<input type="file" name="fupload" onchange="showImage(this);"/>
<img id="pic" src="#" alt="your image" width="200" height="200"/>
Probably you didn't include jQuery!
<script>
function showImage(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
var preview = document.querySelector('#pic'); //-->Added line;
reader.onload = function (e) {
//---Correction is here---
//$('#pic').attr('src',e.target.result).width(200).height(200);
preview.src = reader.result;
};
reader.readAsDataURL(input.files[0]);
}
}
Test it with JsFiddle;
Hi i took this code for file upload using jquery or javascsript in jsfiddle given below
http://jsfiddle.net/KyleMit/d3H9f/
<input type='file' />
<img id="myImg" src="#" alt="your image" />
$(function () {
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#myImg').attr('src', e.target.result);
};
I want to store image in my folder. but the above code show path like
"data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QNkaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjUtYzAyMSA3OS4xNTQ5MTEsIDIwMTMvMTAvMjktMTE6NDc6MTYgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcE1NPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vIiB4bWxuczpzdFJlZj0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL3NUeXBlL1Jlc291cmNlUmVmIyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ9IjY0QzFCQzhBNTEyQzZCNkQwMDA0MDk5OUQ2QUFFMkIzIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkUyOTRFMjVBQUZCQjExRTM4MEMwQkFCRDY1Mjg5Qzk1IiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkUyOTRFMjU5QUZCQjExRTM4MEMwQkFCRDY1Mjg5Qzk1IiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDQyAoTWFjaW50b3NoKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdF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wRKIwxmVg2o9Y1AZSOOoChrzrjN9Er7ikFx733sGjQRrQjVkNZU5HXnqCcD9RWlQMWsQyFxtvuz7b2gtVvemuo11SdCh0e4EwVderho/FWnPHC8YzMe/sgqB2FkFBkZW9UQmUqy3GvSukhgWk8eqJBSn0HFx4y+Hs8zOAaf5l7uMx9YN1F0q+knVnqqZKHUTXlXwyxz+WORQq3H+pX1AXYmoOqHNZqvrM1TUNq+kZr4HTjDy7BgZjvnoM1r1DbR262qmzFyJJC7dQ0CEGO6SUHnb6kKU1AEZ/V/t35LddXuM2gz+3lm2+692qRwEv1jfGWSIRAgjraxHMYmfKPTSVXqYtXrA99iMl3Hqva691CQWoVvbwb8euWTVkbaX9Dc1T8o6ZGKTAIszcSxFbkXtnYdWPpybiYbvbCPJN0FpKBT8rVpg5GBdSNscdwRYxdtXO5aB0W7ck323utPmtklxb6viceZTH6o7dJpdnkU+5zfuUzN7e07uiXl/qb+SOnKnVgjanxxuv0/6fIviYrdv9wG4b+ce8W65+96rS/8A2acd6xyNFa2mv8Xi/H7AMsaAiatXBif4ag+dKVwZS625d2OnpPdIuegskLr/ABU6rIPjjjaOwY9vkaOwRhCOvL2w/wCb+ZR26SU/i6Dufljz3z/X3T7w+3SWkc/7XoKbrY9rz3GdTt93v8HPwitpo6/A45xu8nbvVPiYmvYHzT9vSbTfDZLHuG1h9rL1Htby7udp0af/AOpb62tv0eGr1fDOmMNW5uvv7obxNLjP3mF/13n/APXw/sxfl4kmJ//Z"
but i want path like "E:\yello.png" can u help me?
I want to do is if the user click to browse for files he should see images only no other files. How to do that using jquery?
My problem is I can see and choose other files besides images when i browse.
current output: http://jsfiddle.net/LvsYc/3123/
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#Picture').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
Change your input to:
<input type='file' id="imgInp" accept="image/*" />
http://jsfiddle.net/LvsYc/3124/
The basic code is in Preview an image before it is uploaded codes also are shown in below:
<script type="text/javascript">
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
<body>
<form id="form1" runat="server">
<input type='file' onchange="readURL(this);" />
<img id="blah" src="#" alt="your image" />
</form>
Codes work fine, but it shows broken image icon when there is no img is selected. I tried to use
if($('#img_prev').attr('src',"#"){
$('#img_prev').hide();
}
But it hides all images.
Any help is welcome! Thank you for your time.
Just make the CSS display:none on #blah and then modify your JS to have this function:
function readURL(input) {
var $prev = $('#blah'); // cached for efficiency
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$prev.attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
$prev.show(); // this will show only when the input has a file
} else {
$prev.hide(); // this hides it when the input is cleared
}
}
This should appropriately show/hide the img when the input changes.
By the way, you should really not use inline calls like onchange= if you are using jQuery. Something like this is much better:
<script type="text/javascript">
;(function($){
function readURL(input) {
var $prev = $('#blah');
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$prev.attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
$prev.show();
} else {
$prev.hide();
}
}
$('#imgInput').on('change',function(){
readURL(this);
});
})(jQuery);
</script>
<body>
<form id="form1" runat="server">
<input id="imgInput" type='file' />
<img id="blah" src="#" alt="your image" />
</form>
</body>
This encapsulates all logic in one place, much easier to maintain. The next step, of course, is to have this in an external file rather than on the page, but that is beyond the scope of this.
Alert not come when onchange event in internet explore ?
i am use below code:
<input type="file" onChange="readURL(this)" />
<script src="http://code.jquery.com/jquery-1.8.0.min.js " > </script>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
alert('asf');
reader.onload = function(e) {
//alert(e.target.result);
$('#photoview').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
IE9 doesn't have the FileReader.
See compatibility table at end of this MDN documentation. Note that this document also proposes a solution for compatibility with IE.
for IE you have to use FileSystemObject activex component
for more details check this link :
http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/FileSystemObjectGetFile.htm