Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Created September 9, 2017 09:16
Show Gist options
  • Save Sanix-Darker/436319afcd32638caad72f5a5e38d309 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/436319afcd32638caad72f5a5e38d309 to your computer and use it in GitHub Desktop.
Preview Image
<img id="blah" src="#" alt="Image du blog" style="width: 30%;" />
<input type="file" id="imgInp" name="img" required="required" class="form-control col-md-9 col-xs-12" required="" />
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
function readURL(input,cible) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#'+cible).attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this,'blah');
});
$('#blah').click(function(){
$("#imgInp").trigger('click');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment