开发者

PHP doesn't recognize POST Upload done with HttpClient

开发者 https://www.devze.com 2023-01-18 07:49 出处:网络
Java Code: HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( \"http://localhost/SC/upload.php\");

Java Code:

            HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(
                "http://localhost/SC/upload.php");

        FileBody bin = new FileBody(f3);

        MultipartEntity reqEntity = new MultipartEntity();
        reqEntity.addPart("bin", bin);

        httppost.setEntity(reqEntity);

        System.out
                .println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();

        System.out.println("----------------------------------------");
        System.out.println(response.getStatusLine());
        if (resEntity != null) {
            System.out.println("Response content length: "
                    + resEntity.getContentLength());
            System.out.println("Chunked?: " + resEntity.isChunked());
            System.out.println("Response: "
                    + EntityUtils.toString(resEntity));
        }
        if (resEntity != null) {
            resEntity.consumeContent();
        }

PHP Code:

    <?php
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"开发者_JAVA技巧]["tmp_name"];
  }

print_r ($_FILES);
?> 

Every time I run the Java Code, I always get:

executing request POST http://localhost/SC/upload.php HTTP/1.1 ---------------------------------------- HTTP/1.1 200 OK Response content length: 241 Chunked?: false Response: Upload:

Type:

Size: 0 Kb

Stored in: Array ( [bin] => Array ( [name] => File.tar.lzma [type] => [tmp_name] => [error] => 1 [size] => 0 ) )

I've tested it with normal http upload (through webbrowser, same file) and it works.

What am I doing wrong?

EDIT: f3 is a File (that I KNOW exists, (/home/me/Desktop/File.tar.lzma))


It turns out that it really WAS a php max file size problem, although it under the limit (2M), I didn't know that the java code was adding parts to the file (in the TAR code)

Increasing the limit fixed the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消