2016-06-11 56 views
0

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

@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; 
    } 

图片上传时没有任何错误在android端和服务器端。然而,上传的图片是0字节,他们没有任何数据,我无法查看它们。 php脚本

 <?php 




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


     file_put_contents($path,$decodeImage); 



    ?> 

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

回答

0

我猜想,这可能只是一个错字而不是

file_put_contents($path,$decodeImage); 

你可能是指

file_put_contents($path,$decodedImage); 
+0

哇,我已经错过了。谢谢。 –

+0

在PHP错误日志中,我仍然得到一个更多的错误。未定义的索引:第7行上的/home/melobookco/public_html/multipleupload.php中的图像 [12-Jun-2016 04:54:32 ...您是否知道如何定义该索引? –

+0

你可以显示相关的代码 - 或者如果是上面的代码指出相关的行吗? –