I am using cordova with phonegap to upload camara images to my app so user can select from gallery or camara roll, the problem is:
the posted file is always null i tried all options and all the time the same problem!
here my code
using cordova upload camara plugin i create the following method: openFilePicker
openFilePicker: function (selection) {
var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM;
var options = this.setOptions(srcType);
var func = this.createNewFileEntry;
navigator.camera.getPicture(function cameraSuccess(imageUri) {
console.log(imageUri); // image path is printed OK!
//showing the the console: file:///var/mobile/Container/Data/Applications/377050-7113-4519-9ACB-3C85B1FC6385/tmp/cdv_photo_006.jpg
app.request( {
url: serverPath+"_g.up.php", //here I call the php file to upload the file
dataType: "application/json",
method: "POST",
cache: false,
contentType: false, //using false or multipart.... no difference
processData: false, // using true or false no any difference
data : {file:imageUri},
crossDomain: true,
preloader: true,
statusCode: {
404: function(xhr) {
console.log('page not found');
}
},
beforeSend: function() {
console.log('beforeSend');
},
complete: function() {
console.log('complete');
},
success: function(response) {
console.log('success');
console.log(response);
},
error: function(xhr) {
console.log('error');
console.log(xhr.status);
console.log(xhr.code);
}
});
}, function cameraError(error) {
console.debug("Unable to obtain picture: " + error, "app");
}, options);
},
the php code
header(‘Access-Control-Allow-Origin: *’);
$images = $_FILES[“file”][“name”];
echo json_encode(array(“status”=>$images)); // always $images is null
//print_r(json_encode($_FILES)); // always $images is null
$new_image_name = urldecode($_FILES[“file”][“name”]).".jpg";
move_uploaded_file($_FILES[“file”][“tmp_name”], “upload/”.$new_image_name);
phonegap console:
file:///var/mobile/Container/Data/Applications/377050-7113-4519-9ACB-3C85B1FC6385/tmp/cdv_photo_006.jpg
_g.up.php
beforeSend
success
{“status”:null}
complete
any ideas what I am doing wrong? why the $_FILES[“file”] is always null?
thanks