I have create a Drawing app with custom class, I have named the class "drawView". After Someone has done to draw, he click's a button named "saveBtn", and then its should upload the image to server using php.
Plz look at code below and help me figure it out why its not upload the image.
CreateSingleSignature.java: (I just show you tha main code..Without onCreate etc.)
public class CreateSigleSignature extends Activity implements OnClickListener{
private MainDrawingView drawView;
Button saveBtn;
InputStream inputStream;
Bitmap bm;
public void onClick(View v) {
switch (v.getId()) {
case R.id.save_btn:
try {
drawView.setDrawingCacheEnabled(true);
bm = Bitmap.createBitmap(drawView.getDrawingCache());
executeMultipartPost();
} catch (Exception e) {
Log.e(e.getClass().getName(), e.getMessage());
}
drawView.destroyDrawingCache();
break;
}
}
public void executeMultipartPost() throws Exception {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"http://www.zinman.byethost6.com/up/upload.php");
ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploaded", bab);
reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(
response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
sResponse = reader.readLine();
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Upload Information");
alertDialog.setMessage(sResponse);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
} catch (Exception e) {
// handle exception here
Log.e(e.getClass().getName(), e.getMessage());
}
}
upload.php:
if(isset($_FILES['uploaded'])){
move_uploaded_file($_FILES['uploaded']['tmp_name'], "bvbvb.jpg");
echo $_FILES['uploaded']['tmp_name'] . " ";
echo $_FILES['uploaded']['name'] . " ";
echo $_FILES['uploaded']['type'] . " ";
echo $_FILES['uploaded']['size'];
$data = file_get_contents($_FILES['uploaded']['tmp_name']);
echo $data;
$image = imagecreatefromstring( $data );
move_uploaded_file($image, "bb.jpg");
echo $image;
}
As you can see I create two options to upload the file with php but nothing working. How to fix it??