php - file is not uploading into server in android -
iam uploading image file server while uploading in server in android displaying error message.
<!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 request server not understand.<br /></p> <p>additionally, 404 not found error encountered while trying use errordocument handle request.</p> </body></html>
my php code
<?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 '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 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; ?>
calling function in 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) { }
Comments
Post a Comment