Skip to content

Instantly share code, notes, and snippets.

@jhonnrodr
Last active August 29, 2015 14:12
Show Gist options
  • Save jhonnrodr/1ca113587cbc512e9d1f to your computer and use it in GitHub Desktop.
Save jhonnrodr/1ca113587cbc512e9d1f to your computer and use it in GitHub Desktop.
<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