I have a html file with an image upload form
<form name="logo_photo" id="logo_image_form" enctype="multipart/form-data" action="" method="post">
<input type="file" id="logo_upload" name="uploadfile"/>
</form>
and a jquery script to attemp ajax upload of this form - like this
$(document).ready(function (e) {
$("#logo_upload").on('change', function(event){
$("#logo_image_form").submit();
event.preventDefault();
});
$("#logo_image_form").on('submit', function(event){
event.preventDefault()
$.ajax({
type:'POST',
url: serverUrl+"uploadController/imageuploadAction",
data:$(this).serialize(),
cache:false,
success:function(data){
console.log("success");
console.log(data);
},
error: function(data){
console.log("error");
console.log(data);
}
});
return false;
event.preventDefault();
});
});
and the controller in the codeigniter framework, simply has a small test return, like this -
function imageuploadAction() {
//testing controller
print_r($_FILES);
}
but the return is an empty array. i want to be writing more code to check and upload the image, like performing tests on $_FILES['uploadfile']['tmp_name']
but $_FILES seems to be empty.
What am i missing on this? Any help will be appreciated, Thanks!!