Java Kod:
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-Kodu:
<?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"]["tmp_name"];
}
print_r ($_FILES);
?>
Ben Java kodu çalıştırmak her zaman, hep olsun:
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 ) )
Ben (tarayıcısı aracılığıyla, aynı dosyada), normal http yükleme ile test ettik ve çalışır.
Ben yanlış ne yapıyorum?
EDIT: f3 Dosya (Ben var biliyorum, (/ home / ben / Desktop / File.tar.lzma))