Uploading multiple image on php server from android -



Uploading multiple image on php server from android -

help specific server side php code don't have knowledge of php , have upload 3 images android php page.

i have tried many methods , searched no tutorial or didn't help me android code working properly. dns configured images aren't shown @ server side. please help me java code.

php:

<?php if ($_files["file1"]["error"] > 0) { header("http/1.1 400 bad request"); echo "error: " . $_files["file1"]["error"] . "<br />"; } else if ($_files["file2"]["error"] > 0) { header("http/1.1 400 bad request"); echo "error: " . $_files["file1"]["error"] . "<br />"; } else if ($_files["file3"]["error"] > 0) { header("http/1.1 400 bad request"); echo "error: " . $_files["file1"]["error"] . "<br />"; } else { if ($_files["file1"]["error"] > 0) { echo "error: " . $_files["file1"]["error"] . "<br />"; } else { echo "upload: " . $_files["file1"]["name"] . "<br />"; echo "type: " . $_files["file1"]["type"] . "<br />"; echo "size: " . ($_files["file1"]["size"] / 1024) . " kb<br />"; echo "stored in: " . $_files["file1"]["tmp_name"]. "<br />"; } //$target_path = "uploads/"; $target_path = "elp/pendingimages/"; $target_path = $target_path . basename( $_files['file1']['name']); if(move_uploaded_file($_files['file1']['tmp_name'], $target_path)) { echo "the file ". basename( $_files['file1']['name']). " has been uploaded"; } else{ echo "there error uploading file, please seek again!"; } if ($_files["file2"]["error"] > 0) { echo "error: " . $_files["file2"]["error"] . "<br />"; } else { echo "upload: " . $_files["file2"]["name"] . "<br />"; echo "type: " . $_files["file2"]["type"] . "<br />"; echo "size: " . ($_files["file2"]["size"] / 1024) . " kb<br />"; echo "stored in: " . $_files["file2"]["tmp_name"]. "<br />"; } //$target_path = "uploads/"; $target_path = "elp/pendingimages/"; $target_path = $target_path . basename( $_files['file2']['name']); if(move_uploaded_file($_files['file2']['tmp_name'], $target_path)) { echo "the file ". basename( $_files['file2']['name']). " has been uploaded"; } else{ echo "there error uploading file, please seek again!"; } if ($_files["file3"]["error"] > 0) { echo "error: " . $_files["file3"]["error"] . "<br />"; } else { echo "upload: " . $_files["file3"]["name"] . "<br />"; echo "type: " . $_files["file3"]["type"] . "<br />"; echo "size: " . ($_files["file3"]["size"] / 1024) . " kb<br />"; echo "stored in: " . $_files["file3"]["tmp_name"]. "<br />"; } //$target_path = "uploads/"; $target_path = "elp/pendingimages/"; $target_path = $target_path . basename( $_files['file3']['name']); if(move_uploaded_file($_files['file3']['tmp_name'], $target_path)) { echo "the file ". basename( $_files['file3']['name']). " has been uploaded"; } else{ echo "there error uploading file, please seek again!"; } } ?>

java:

public class tryprojectactivity extends activity { inputstream is; int pic_count = 0; bitmap bitmap=null; fileinputstream in1,in2,in3; bufferedinputstream buf; @override public void oncreate(bundle icicle) { super.oncreate(icicle); setcontentview(r.layout.main); seek { in1 = new fileinputstream("/sdcard/1.jpg"); } grab (filenotfoundexception e2) { // todo auto-generated grab block e2.printstacktrace(); } seek { in2 = new fileinputstream("/sdcard/2.jpg"); } grab (filenotfoundexception e1) { // todo auto-generated grab block e1.printstacktrace(); } seek { in3 = new fileinputstream("/sdcard/3.jpg"); } grab (filenotfoundexception e1) { // todo auto-generated grab block e1.printstacktrace(); } bitmap bitmaporg1 = bitmapfactory.decodestream(in1); bytearrayoutputstream bao1 = new bytearrayoutputstream(); bitmaporg1.compress(bitmap.compressformat.jpeg, 90, bao1); byte [] imagearray1 = bao1.tobytearray(); string ba1=base64.encode(imagearray1); bitmap bitmaporg2 = bitmapfactory.decodestream(in2); bytearrayoutputstream bao2 = new bytearrayoutputstream(); bitmaporg2.compress(bitmap.compressformat.jpeg, 90, bao2); byte [] imagearray2 = bao2.tobytearray(); string ba2=base64.encode(imagearray2); bitmap bitmaporg3 = bitmapfactory.decodestream(in3); bytearrayoutputstream bao3 = new bytearrayoutputstream(); bitmaporg3.compress(bitmap.compressformat.jpeg, 90, bao3); byte [] imagearray3 = bao3.tobytearray(); string ba3=base64.encode(imagearray3); list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(3); namevaluepairs.add(new basicnamevaluepair("image1",ba1)); namevaluepairs.add(new basicnamevaluepair("image2",ba2)); namevaluepairs.add(new basicnamevaluepair("image3",ba3)); try{ httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("http://helpdesk.cispl.com/upload_file.php"); urlencodedformentity obj = new urlencodedformentity(namevaluepairs); obj.setchunked(true); httppost.setentity(obj); httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); //is = entity.getcontent(); httpclient.getconnectionmanager().shutdown(); } catch(exception e){ //commonfunctions.writelog(ctx.getclass().tostring(), e.tostring()); //commonfunctions.showtoast(ctx, "unable post captured image file: " + //e.tostring()); } }

looks php correct.

on device utilize http post request multipartentity info type. read more here

edit

example link:

you have download additional libraries multipartentity running!

1) download httpcomponents-client-4.1.zip http://james.apache.org/download.cgi#apache_mime4j , add together apache-mime4j-0.6.1.jar project.

2) download httpcomponents-client-4.1-bin.zip http://hc.apache.org/downloads.cgi , add together httpclient-4.1.jar, httpcore-4.1.jar , httpmime-4.1.jar project.

3) utilize illustration code below.

private defaulthttpclient mhttpclient; public servercommunication() { httpparams params = new basichttpparams(); params.setparameter(coreprotocolpnames.protocol_version, httpversion.http_1_1); mhttpclient = new defaulthttpclient(params); } public void uploaduserphoto(file image1, file image2, file image3) { seek { httppost httppost = new httppost("some url"); multipartentity multipartentity = new multipartentity(httpmultipartmode.browser_compatible); multipartentity.addpart("title", new stringbody("title")); multipartentity.addpart("nick", new stringbody("nick")); multipartentity.addpart("email", new stringbody("email")); multipartentity.addpart("description", new stringbody(settings.share.text)); multipartentity.addpart("file1", new filebody(image1)); multipartentity.addpart("file2", new filebody(image2)); multipartentity.addpart("file3", new filebody(image3)); httppost.setentity(multipartentity); mhttpclient.execute(httppost, new photouploadresponsehandler()); } grab (exception e) { log.e(servercommunication.class.getname(), e.getlocalizedmessage(), e); } } private class photouploadresponsehandler implements responsehandler { @override public object handleresponse(httpresponse response) throws clientprotocolexception, ioexception { httpentity r_entity = response.getentity(); string responsestring = entityutils.tostring(r_entity); log.d("upload", responsestring); homecoming null; } }

php android image file-upload

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -