简体   繁体   中英

Android file upload to php script problems on some devices

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

我自己发现了问题:修复了一些php.ini参数(最大内存,max_post_size),现在上传正常

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM