i got problem in order to upload my image, after sucessfull image preview in jquery to my server. It shows file is not defined in the form.append statement or action.
Tried to fix it on my own but couldn`t find a solution that works.Could you advice me or help me a little bit code is following.
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
$('#imagePreview').css('background-image', 'url('+e.target.result +')');
$('#imagePreview').hide();
$('#imagePreview').fadeIn(650);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imageUpload").change(function() {
readURL(this);
var formData = new FormData();
formData.append('formData', file);
$.ajax({
url: 'assets/uploadProfilepic.php', //Server script to process data
type: 'POST',
data: formData,
contentType: false,
processData: false,
//Ajax events
success: function(html){
alert(html);
}
});
});
The HTML Part
<div class="avatar-upload">
<div class="avatar-edit">
<input type='file' id="imageUpload" accept=".png, .jpg, .jpeg" name="file" />
<label for="imageUpload"></label>
</div>
<div class="avatar-preview">
<div id="imagePreview" style="background-image: url(http://i.pravatar.cc/500?img=7);">
</div>
</div>
</div>
Uncaught ReferenceError: file is not defined but it should be or i dont really understand
Please someone could help me a little bit or give a solution. Thanks and Greets