【问题标题】:Cordova fileupload not working on Android, $_FILES is emptyCordova 文件上传无法在 Android 上运行,$_FILES 为空
【发布时间】:2016-05-27 11:11:13
【问题描述】:

我正在使用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)));
}

有什么建议吗?

谢谢! :)

【问题讨论】:

    标签: php android cordova cordova-plugins file-transfer


    【解决方案1】:

    如果我将 cordova fileupload 插件选项设置为:chunkedMode = false 它可以工作...我也更改了 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;
    

    希望它可以帮助其他人:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-11
      • 2021-04-30
      • 2016-10-15
      • 2015-01-01
      • 1970-01-01
      • 2013-03-21
      • 2019-11-25
      • 1970-01-01
      相关资源
      最近更新 更多