title: Java applet to upload a file
body: <p>I am looking for a  Java applet to read a file from client machine and creat a POST request for PHP server uploading.</p>
  
  <p>PHP script on server should  receive the file as normal file upload in FORM submit.
  I am using the following code. The file contents are passed to PHP script
  but they are not correctly converted to an image.</p>
  
  <pre><code>//uploadURL will be a url of PHP script like
  // http://www.example.com/uploadfile.php
  
  URL url = new URL(uploadURL);
  HttpURLConnection con = (HttpURLConnection)url.openConnection();
  con.setRequestMethod("POST");
  con.setDoInput(true);
  con.setDoOutput(true);
  
  InputStream is = new FileInputStream("C://img.jpg");
  OutputStream os = con.getOutputStream();
  byte[] b1 = new byte[10000000];
  int n;
  while((n = is.read(b1)) != -1) {
  os.write("hello" , 0, 5);
  test += b1;
  
  }
  con.connect();
  </code></pre>