I am using ajax to upload a photo in Laravel. URL is working fine but data is not receiving in function in a controller.
HTML Code
<input type="file" id="photo_input">
Ajax / JQuery Code
$('#photo_input').change(function(){
var formData = new FormData('#photo_input');
$.ajax({
type:'POST',
url: home_url+'/upload-image',
data:formData,
cache:false,
enctype: 'multipart/form-data',
contentType: false,
processData: false,
success:function(data){
console.log("success");
console.log(data);
},
error: function(data){
console.log("error");
console.log(data);
}
});
});
PHP Code in Controller
public function uploadImage(){
$data = Input::all();
print_r($data);
}
Response from function in a controller
array(
);
I haven't used <form>
tag in html, I want to upload it directly. Do I need to add <form>
tag?
Is there anything which is missing?