Forked from jhonnrodr/Subir imagen por ajax automaticamente
Last active
August 29, 2015 14:14
-
-
Save bran921007/3ae23e4cdefa5941da73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img onclick="jQuery('#file').click()" id="imageUpload" src="uploads/images/flyer_picture/{{$fly->detail}}" style="width:200px;height:200px;"/> | |
<input type="file" id="file" name="pic" style="display: none;"/> | |
<script> | |
//------------------------------------------- | |
//Subir imagen | |
$("#file").change(function(){ | |
readURL(this); | |
var inputFileImage = document.getElementById("file"); | |
var file = inputFileImage.files[0]; | |
var data = new FormData(); | |
data.append('file',file); | |
$.ajax({ | |
url:"/flyerPicture", | |
type:'POST', | |
contentType:false, | |
data:data, | |
processData:false, | |
cache:false}).done(function(data){ | |
if(file!=undefined){ | |
$("#timelinePost").prepend("<img src='"+file.name+"' >"); | |
} | |
}); | |
}); | |
function readURL(input) { | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
$('#imageUpload').attr('src', e.target.result); | |
} | |
reader.readAsDataURL(input.files[0]); | |
} | |
} | |
//END Subir imagen | |
//------------------------------------------ | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment