簡體   English   中英

文件沒有上傳到android中的服務器

[英]file is not uploading into server in android

iam將圖像文件上傳到服務器,同時上傳到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();
    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)
                    {

                    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM