2

我正在尝试将文件从android上传到服务器。我使用php作为服务器。这不起作用,我找不到原因。请帮我。

HttpClient client = new DefaultHttpClient(); 
            HttpPost post = new HttpPost("http://ganji.snucse.org/upload.php");
            MultipartEntity reqEntity = new MultipartEntity();  
            reqEntity.addPart("imageFile", new FileBody(img1_file));
            try {
                reqEntity.addPart("imageTitle", new StringBody("imageTitle"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
             post.setEntity(reqEntity);

            try {
                HttpResponse response = client.execute(post);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

这是java代码和

  1 <?php
  2
  3 $uploaddir = './uploads/';
  4 $file = basename($_FILES['imageFile']['imageTitle']);
  5 $uploadfile = $uploaddir.$file;
  6
  7
  8 echo 'Debugging Info:';
  9 print_r($_FILES);
 10
 11 print "</pre>";
 12
 13 ?>

这是php代码

这行不通。我不明白为什么。请帮我。

4

1 回答 1

0

我在工作版本中的唯一区别是:

$file = file_get_contents($_FILES['imageFile']['tmp_name']));
于 2013-03-11T05:42:58.890 回答