I'm trying to upload a file using Slim 2. But I'm lost for how I can access the $_FILES[] parameter.
I have the following AJAX call to index.php from JQuery.
$("form[name='photo_upload']").on('submit',(function() {
var location='{{site.uri.image}}/profile/{{bio.user_id}}';
var fd=new FormData(this);
fd.append('id',{{bio.user_id}});
fd.append('loc',location);
$.ajax({
'url': '{{site.uri.public}}/bio?id={{user.id}}&action=update',
'type': "POST",
'data': fd,
'cache': false,
'processData': false,
'success': function(data){
var new_loc='{{site.uri.image}}/profile/'+data['photo_loc'];
$("#frame").attr("src",new_loc);
$('.editbox.'+cls).addClass("hidden");
}
});
}));
Now I pickup the request with the following function in index.php using Slim 2.
$app->post('/bio/?', function () use ($app) {
$id=$app->request->params('id');
$loc=$app->request->params('loc');
$file = $_FILES['image'];
$controller = new TE\UserController($app);
$controller->updateUserPhoto($id, $file, $loc);
$ret=$controller->getUserBio($id, 'photo');
error_log($ret);
echo json_encode(array('photo_loc' => $ret));
});
and get the following error
Undefined index: image
at the line containing
$file = $_FILES['image'];
on the above code.
I would really appreciate some help on this.
Edit
I get the following when I var_dump[$_FILES].
array(1) { ["image"]=> array(5) { ["name"]=> string(8) "1a_1.PNG" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(24) "C:\xampp\tmp\php585C.tmp" ["error"]=> int(0) ["size"]=> int(19762) } }
It seems $_FILES['image'] and all the file info are there.
I even did an
isset($_FILES['image'])
to check and even that returned true.
So why cant I retrieve if its already there?