duanming7833 2015-11-04 15:09
浏览 44
已采纳

Android文件上传到某些设备上的php脚本问题

In my android app I upload some files to a php script. The code works fine on my tablet, but on some other devices, the upload failes. The size of the files are the some on the devices.

My upload code:

 HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("myurl"
                + "/Mysql_Filesave.php");
        JSONObject json = new JSONObject();

        json.put("Type", type);
        json.put("FileName", files[i].getName());
        json.put("LocalPath", path);
        JSONArray postjson = new JSONArray();
        postjson.put(json);


        // Post the data:
        httppost.setHeader("json", json.toString());
        httppost.getParams().setParameter("jsonpost", postjson);

        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        FileBody fileBody = new FileBody(files[i]);
        reqEntity.addPart("file", fileBody);
        httppost.setEntity(reqEntity);      

        HttpResponse response = httpclient.execute(httppost);

My PHP Code for checking if there is a file:

if (!isset($_FILES['file']['tmp_name'])) {      
    die("No file available");
}

So some devices die on this check. The files are about 10 megabytes big. On the php server I allow files up to 50M.

What can the problem be? I don't have a clue, because on some devices it works, on other not.

Best regards, Peter

  • 写回答

1条回答 默认 最新

  • duandazhen7306 2015-11-10 07:52
    关注

    Found the problem myself: Fixed some php.ini parameters (max memory, max_post_size), now the upload is working

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度