I am using the cordova filetransfer plugin to upload some pictures to server. It works well on my localhost (Android & iOS), but on my server it only works on iOS. With Android the $_FILES array is empty...
The filetransfer plugin fires the uploadSuccess callback, but i can't get the picture server side...
Server side:
public function upload_img_api(){
file_put_contents('test.txt', print_r($_FILES, true)); //<-test.txt returns empty array :(
$path_parts = pathinfo($_FILES["file"]["tmp_name"]);
$extension = strtolower(substr($path_parts['extension'], 0, strpos($path_parts['extension'], "?")));
$extension = ($extension) ? ".".$extension : ".jpg";
$image_size = getimagesize($_FILES["file"]["tmp_name"]);
$image_w = $image_size[0];
$image_h = $image_size[1];
$megapixel = $image_w * $image_h;
$ratio = $this->getResizeRatio($megapixel);
$image_name = "api_image_".time().$extension;
if (!move_uploaded_file($_FILES["file"]["tmp_name"], DENT_UPLOAD_TEMP.$image_name)){
die(json_encode(array('Result' => "ERROR", "MESSAGE" => 'COULDNT FIND FILE')));
}
$thumb_path = $this->generate_thumbnail(DENT_UPLOAD_TEMP.$image_name, DENT_UPLOAD_TEMP.'thumb_'.$image_name);
$resize_image_path = $this->generate_thumbnail(DENT_UPLOAD_TEMP.$image_name, DENT_UPLOAD_TEMP.$image_name, array($image_w/$ratio, $image_h/$ratio));
die(json_encode(array('file_name' => $image_name)));
}
Any advice?
Thanks! :)
If I set the cordova fileupload plugin option to: chunkedMode = false it works... I changed te fileKey as well, now you have to check for $_FILES["fileUpload"]["tmp_name"] on server side.
Here are the working options:
options.fileKey="fileUpload";
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.httpMethod="POST";
options.chunkedMode=false;
Hope it helps others :)