Hallo,
Ik zit al tijdje te prutsen om een file via java te posten naar een php-file.
Telkens geeft hij terug dat het chuncked is. Wat doe ik fout?
en dan naar deze php-file:
merci
Ik zit al tijdje te prutsen om een file via java te posten naar een php-file.
Telkens geeft hij terug dat het chuncked is. Wat doe ik fout?
Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| package org.apache.http.examples.entity.mime; import java.io.File; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; /** * Example how to use multipart/form encoded POST request. */ public class FtpConnection{ public FtpConnection(String file) throws Exception { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("link naar php file"); FileBody bin = new FileBody(new File(file)); StringBody comment = new StringBody("A binary file of some kind"); MultipartEntity reqEntity = new MultipartEntity(); reqEntity.addPart("bin", bin); reqEntity.addPart("comment", comment); 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()); } if (resEntity != null) { resEntity.consumeContent(); } } } |
en dan naar deze php-file:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| <?php $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> |
merci