Cordova 文件上传无法在 Android 上运行,$_FILES 为空
Cordova fileupload not working on Android, $_FILES is empty
我正在使用 cordova 文件传输插件将一些图片上传到服务器。它在我的本地主机 (Android & iOS) 上运行良好,但在我的服务器上它仅在 iOS 上运行。 Android $_FILES 数组为空...
文件传输插件触发 uploadSuccess 回调,但我无法获取图片服务器端...
服务器端:
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)));
}
有什么建议吗?
谢谢! :)
如果我将 cordova fileupload 插件选项设置为:chunkedMode = false 它有效...我也更改了 te fileKey,现在您必须在服务器端检查 $_FILES["fileUpload"]["tmp_name"]。
以下是工作选项:
options.fileKey="fileUpload";
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.httpMethod="POST";
options.chunkedMode=false;
希望对其他人有帮助:)
我正在使用 cordova 文件传输插件将一些图片上传到服务器。它在我的本地主机 (Android & iOS) 上运行良好,但在我的服务器上它仅在 iOS 上运行。 Android $_FILES 数组为空...
文件传输插件触发 uploadSuccess 回调,但我无法获取图片服务器端...
服务器端:
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)));
}
有什么建议吗?
谢谢! :)
如果我将 cordova fileupload 插件选项设置为:chunkedMode = false 它有效...我也更改了 te fileKey,现在您必须在服务器端检查 $_FILES["fileUpload"]["tmp_name"]。
以下是工作选项:
options.fileKey="fileUpload";
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
options.httpMethod="POST";
options.chunkedMode=false;
希望对其他人有帮助:)