0

我正在将图像文件上传到服务器,同时在 android 中上传到服务器它显示错误消息。

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>Your browser sent a request that this server could not understand.<br /></p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

我的 PHP 代码

<?php
header('Content-type: text/xml');
include_once('registration_db_con.php');
$content='<?xml version="1.0" encoding="utf-8"?><Kudos_Image><Photos>';

   $filename=basename($_FILES['uploaded_file']['name']);
  // print_r ($filename);
   $poto_title=explode(".",$filename);

   $ext = pathinfo($filename, PATHINFO_EXTENSION);

   $r = mysql_query("SHOW TABLE STATUS LIKE 'photos'");
   $row = mysql_fetch_array($r);
   $Auto_increment = $row['Auto_increment'];
   mysql_free_result($r);

   $file_name="kudoskudos_img_".$Auto_increment.'.'.$ext;

   $target_Path="../uploads/photos/".$file_name;


   $arr =  array('gif','png','jpg','jpeg');
   if(in_array($ext,$arr))
   {
       $copied = move_uploaded_file ($_FILES['uploaded_file']['tmp_name'], $target_Path);
      $date=date("Y-m-d H:i:s");
       $disp_module="INSERT INTO photos(file_name,photo_title,album_id,caption,views,createdon,createdby,editedon,status) VALUES('".$file_name."','".$poto_title[0]."','".$_POST['album_id']."','".$_POST['caption']."','0',now(),'".$_POST['user_id']."',now(),'1')";
       $sql=mysql_query($disp_module);  
       $id=mysql_insert_id(); 

       if($id)
       {
             $content.="<Insert_Photos>".$id."</Insert_Photos>";
       }
       else
       {
            $content.="<Insert_Photos>0</Insert_Photos>";
       }


  }

  $content.='</Photos></Kudos_Image>';
  echo $content;


 ?>

在android中调用函数

  HttpClient httpClient = new DefaultHttpClient();
  HttpPost postRequest = new HttpPost(com.mythrii.kudoskudos.Utility.urlpath+"webservices/upload_kudos_img.php");

                byte[] data = IOUtils.toByteArray(is);
                InputStreamBody isb= new InputStreamBody(new ByteArrayInputStream(data), convertMediaUriToPath(ImageCaptureUri));

                MultipartEntity multipartContent = new MultipartEntity();
                multipartContent.addPart("uploaded_file", isb);
                multipartContent.addPart("user_id", new StringBody(""+user_id));
                multipartContent.addPart("album_id", new StringBody(""+album_id));
                multipartContent.addPart("caption", new StringBody(""));

                postRequest.setEntity(multipartContent);
                HttpResponse response = httpClient.execute(postRequest);
                HttpEntity entity = response.getEntity();
4

1 回答 1

2
    try
                    {
                        //Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
                        Bitmap bm = BitmapFactory.decodeFile(FileUrlimg);
                        HttpClient client = new DefaultHttpClient();
                        HttpPost request = new HttpPost(URLimg);

                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        bm.compress(CompressFormat.JPEG, 100, bos);
                        byte[] data = bos.toByteArray();
                        if(data.length>5)
                        {
                            ByteArrayBody bab = new ByteArrayBody(data, "photo.jpg");
                            MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                            reqEntity.addPart("image", bab);
                            request.setEntity(reqEntity);

                            HttpResponse response = client.execute(request);
                            HttpEntity entity = response.getEntity();
                            if(response.getStatusLine().getStatusCode()==200)
                            {
    //Uploaded                  

                            }

                        Log.e("log_tag img aft", "Res "+response.getStatusLine().getStatusCode() +"  : "+imgstoupload+":text "+EntityUtils.toString(entity) );
                        }
                        }
                    catch(Exception e)
                    {

                    }
于 2013-04-05T05:21:58.493 回答