I have page where users can upload a photo to the browser with jQuery but I am now trying to figure how to actually save the photo by sending it to a php script. I understand the php side but don't know how with Jquery to send the photo to php. Do I need to put the input within a form?
jQuery
$(document).ready(function() {
var readURL = function(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.profile-pic').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$(".file-upload").on('change', function(){
readURL(this);
});
$(".upload-button").on('click', function() {
$(".file-upload").click();
});
});
HTML
<div class="container">
<div class="row">
<div class="col-xs-6 test">
<h1> Upload Profile Image </h1>
<div class="circle">
<!-- User Profile Image -->
<img class="profile-pic" src="https://source.unsplash.com/300x300">
</div>
<div class="p-image">
<i class="fa fa-camera upload-button"></i>
<form>
<input class="file-upload" id="userImage" type="file" accept="image/*"/>
</form>
</div>
</div>
</div>
</div>