|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
กระทู้ #2340 [Java] (จาก IP: 210.86.131.40)
อยากขอcode j2me ที่เก็บไฟล์รูปภาพลงเครื่องserver
อยากขอcode j2me ที่เก็บไฟล์รูปภาพลงเครื่องserver หน่อยคับ ขอบคุนคับ
|
จากคุณ
:
nong / hiphop_kub@hotmail.com [2008-10-17 00:11:49]
|
|
ความคิดเห็น #27179 (จาก IP: 58.8.185.214)
import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; import java.util.Hashtable; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; public class HttpMultipartRequest { static final String BOUNDARY = "----------V2ymHFg03ehbqgZCaKO6jy"; byte[] postBytes = null; String url = null; public HttpMultipartRequest(String url, Hashtable params, String fileField, String fileName, String fileType, byte[] fileBytes) throws Exception { this.url = url; String boundary = getBoundaryString(); String boundaryMessage = getBoundaryMessage(boundary, params, fileField, fileName, fileType); String endBoundary = "\r\n--" + boundary + "--\r\n"; ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(boundaryMessage.getBytes()); bos.write(fileBytes); bos.write(endBoundary.getBytes()); this.postBytes = bos.toByteArray(); bos.close(); } String getBoundaryString() { return BOUNDARY; } String getBoundaryMessage(String boundary, Hashtable params, String fileField, String fileName, String fileType) { StringBuffer res = new StringBuffer("--").append(boundary).append("\r\n"); Enumeration keys = params.keys(); while(keys.hasMoreElements()) { String key = (String)keys.nextElement(); String value = (String)params.get(key); res.append("Content-Disposition: form-data; name=\"").append(key).append("\"\r\n") .append("\r\n").append(value).append("\r\n") .append("--").append(boundary).append("\r\n"); } res.append("Content-Disposition: form-data; name=\"").append(fileField).append("\"; filename=\"").append(fileName).append("\"\r\n") .append("Content-Type: ").append(fileType).append("\r\n\r\n"); return res.toString(); } public byte[] send() throws Exception { HttpConnection hc = null; InputStream is = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] res = null; try { hc = (HttpConnection) Connector.open(url); hc.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + getBoundaryString()); hc.setRequestMethod(HttpConnection.POST); OutputStream dout = hc.openOutputStream(); dout.write(postBytes); dout.close(); int ch; is = hc.openInputStream(); while ((ch = is.read()) != -1) { bos.write(ch); } res = bos.toByteArray(); } catch(Exception e) { e.printStackTrace(); } finally { try { if(bos != null) bos.close(); if(is != null) is.close(); if(hc != null) hc.close(); } catch(Exception e2) { e2.printStackTrace(); } } return res; } } |
จากคุณ
:
sup98 [2008-10-17 09:41:55]
|
|
ความคิดเห็น #27180 (จาก IP: 58.8.185.214)
<?php $filesize = filesize($_FILES['upload_field']['tmp_name']); echo "The uploaded file size is " . $filesize . " bytes\n"; foreach($_POST as $key => $value) { echo "Parameter name: " . $key . ", value: " . $value . "\n"; } ?> |
จากคุณ
:
sup98 [2008-10-17 09:43:05]
|
|
ความคิดเห็น #27181 (จาก IP: 58.8.185.214)
byte[] fileBytes = getFileBytes(); //retrieve file bytes with your own code Hashtable params = new Hashtable(); params.put("custom_param", "param_value"); params.put("custom_param2", "param_value2"); HttpMultipartRequest req = new HttpMultipartRequest( "http://www.server.com/uploadScript.php", params, "upload_field", "original_filename.png", "image/png", fileBytes ); byte[] response = req.send(); |
จากคุณ
:
sup98 [2008-10-17 09:44:17]
|
|
ความคิดเห็น #27182 (จาก IP: 210.86.131.61)
คือเปนมือใหม่เขียนj2meอ่ะคับ พอจะอธิบายcodeที่ให้มาคร่าวๆด้ายมั้ยคับ ว่าแต่ละส่วนคืออะรัย คือ มั่ยค่อยเข้าจัยว่าเรา จะเอารูปที่เรามีไปใส่ตรงตำแหน่งไหนมั่งอ่ะคับ แล้วcode นี้สามารถลงรูปได้หลายรูปมั้ยคับ ขอบคุนมากคับ |
จากคุณ
:
nong / hiphop_kub@hotmail.com [2008-10-18 00:25:23]
|
|
|
- - - - - - - - - - - - - - ผู้ให้การสนับสนุน- - - - - - - - - - - - - -
|
|
|
|
|