我有一个页面,用户可以使用jQuery将照片上传到浏览器,但我现在正试图通过将照片发送到php脚本来实现如何实际保存照片。我理解php方面但不知道Jquery如何将照片发送到php。我是否需要将输入放在表单中?
的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>