doutuo6689 2014-12-25 06:37
浏览 29

绘图应用程序 - 将绘图作为图像上载到PHP服务器

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??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题