【问题标题】:Image uploaded is 0 bytes上传的图片为 0 字节
【发布时间】:2016-06-11 19:29:03
【问题描述】:

我正在使用以下任务使用 php 将多个图像从 android 设备上传到服务器。

    @Override
    protected String doInBackground(String... params) {
        try {

            String url = "http://aerialssnip.com/multipleupload.php/";
            int i = Integer.parseInt(params[0]);
            Bitmap bitmap = decodeFile(map.get(i));
            HttpClient httpClient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            HttpPost httpPost = new HttpPost(url);
            entity = new MultipartEntity();

            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            byte[] data = bos.toByteArray();

            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost,
                    localContext);
            sResponse = EntityUtils.getContentCharSet(response.getEntity());

            System.out.println("sResponse : " + sResponse);


        } catch (Exception e) {
            if (dialog.isShowing())
                dialog.dismiss();
            Log.e(e.getClass().getName(), e.getMessage(), e);

        }
        return sResponse;
    }

图片在安卓端和服务器端都没有任何错误上传。但是,上传的图像是 0 字节,它们没有任何数据,我无法查看它们。 php脚本

      <?php




      $name = $_POST["name"];
     $image = $_POST["IMAGE"];
     $decodedImage = base64_decode("$image");


       file_put_contents($path,$decodeImage);



     ?>

有人知道我的代码中可能存在什么问题吗?任何帮助将不胜感激。提前致谢。

【问题讨论】:

    标签: php android image-uploading


    【解决方案1】:

    我想这可能只是一个错字

    代替

    file_put_contents($path,$decodeImage);
    

    你可能是说

    file_put_contents($path,$decodedImage);
    

    【讨论】:

    • 在 php 错误日志中,我仍然遇到另一个错误。未定义的索引:第 7 行 /home/melobookco/public_html/multipleupload.php 中的图像 [12-Jun-2016 04:54:32...您知道我如何定义该索引吗?
    • 你能显示相关代码吗?或者如果是上面的代码,请指出相关行?
    • 在上述代码中看不到任何会生成该消息的内容。如果 $_POST["IMAGE"] 没有定义,它会产生消息 Undefined index: IMAGE
    猜你喜欢
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 2017-01-16
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多