Android uploads images and adds parameters to PHP receive

Source: Internet
Author: User

PHP side Receive code:

     Public functionGet_file () {$local _path= "./public/daixu_picture/figure/";//storage path for server files        $img _name=basename($_files[' UploadedFile '] [' name ']);//the image name in the server (UploadedFile is the key value name, can be set by itself)        $target _path=$local _path.$img _name; $result=Move_uploaded_file($_files[' UploadedFile '] [' Tmp_name '],$target _path); if($result) {            Echo"Upload succeeded"; } Else{            Echo"Upload Failed"; }    }

Android Side code:

/** Function: Upload image and Carry parameters * Incoming parameter: Http_url (server Destination address), filepath (address of native picture)*/     Public voidUploadimage (FinalString Http_url,FinalString filepath) {        NewThread (NewRunnable () {@Override Public voidrun () {Try{File File=NewFile (filepath); if(!file.exists ()) {LOG.I ("Error", "file does not exist"); } HttpClient Client=Newdefaulthttpclient (); HttpPost Post=NewHttpPost (Http_url); Filebody Filebody=NewFilebody (file, "Image/jpeg"); Multipartentity Entity=Newmultipartentity (); Entity.addpart ("UploadedFile", filebody);//UploadedFile is the name of the key value for the image uploadEntity.addpart ("Key_app",NewStringbody ("1"));//sets the parameter to pass in, Key_app is the key value namepost.setentity (entity); HttpResponse Response=Client.execute (POST); if(Response.getstatusline (). Getstatuscode () = = 200) {httpentity httpentity=response.getentity (); String result= Entityutils.tostring (httpentity, "Utf-8"); LOG.E ("Returned results", result); }                }Catch(Exception e) {e.printstacktrace ();    }}). Start (); }

Android uploads images and adds parameters to PHP receive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.