I'm trying to upload a text file to my website server and from the emulator works ok, but when I try from my mobile phone i get `42-Error in http` when I print out `e.getMessage()` in the catch block. What could be the problem?
.java file:
.php file:Code:ByteArrayOutputStream bos=null; InputStream is=null; OutputStream os=null; HttpConnection hc=null; String url="http://{domain}.com/{folder}/index.php"; String boundary="----------V2ymHFg03ehbqgZCaKO6jy"; Object file=getNote(mainScreen.getSelectedIndex()); //returns a reference to the selected item in a `List` screen String fileName=(String) file; fileName=fileName.substring(0,fileName.length()-4); //removes the `.txt` from the filename byte[] fileBytes=fileName.getBytes(); StringBuffer sb=new StringBuffer("--").append(boundary).append("\r\n"); sb.append("Content-Disposition: form-data;name=\"").append("file").append("\";filename=\"").append(fileName).append("\"\r\n").append("Content-Type: ").append("text/plain").append("\r\n\r\n"); String boundaryMessage=sb.toString(); String endBoundary="\r\n--"+boundary+"--\r\n"; bos=new ByteArrayOutputStream(); bos.write(boundaryMessage.getBytes()); bos.write(fileBytes); bos.write(endBoundary.getBytes()); byte[] postBytes=bos.toByteArray(); bos.close(); hc=(HttpConnection) Connector.open(url,Connector.READ_WRITE); hc.setRequestMethod(HttpConnection.POST); hc.setRequestProperty("User-Agent","HttpMidlet/0.2"); hc.setRequestProperty("Content-Type", "multipart/form-data; boundary="+boundary); os=hc.openOutputStream(); os.write(postBytes); os.close(); hc.close(); int ch; is = hc.openInputStream(); String res = null; bos = new ByteArrayOutputStream(); while((ch=is.read())!=-1) { bos.write(ch); } res=bos.toString(); is.close(); bos.close();
Code:$root = "/home/{username}/public_html"; $dir = "/{folder}/"; $name = $_FILES[ "file" ][ "name" ]; $tmp_name = $_FILES[ "file" ][ "tmp_name" ]; $filesize = filesize( $tmp_name ); echo $root.$dir.$name.".txt"; move_uploaded_file( $tmp_name , $root.$dir.$name.".txt" );

Reply With Quote

