Upload Image
Well I've created a php file which uploads images. If you access the php file directly and upload the image in the browser, the works fine. However, I'm trying to do this through a Java Applet.
I have this html form:
<form method='post' enctype='multipart/form-data'>
<input name='userfile' type='file' id='userfile' />
<input name='upload' type='submit' id='upload' value='Upload'>
</form>
And here is my Java code, which unfortunately doesn't work.
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
publicclass Upload{
publicstaticvoid main(String[] args){
URL url;
HttpURLConnection urlConn;
DataOutputStream printout;
try{
url =new URL("http://www.mydomain.com/upload_background.php");
urlConn = (HttpURLConnection)url.openConnection();
urlConn.setDoInput(true);
urlConn.setDoOutput(false);
urlConn.setUseCaches(false);
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty("Content-Type","multipart/form-data");
String content ="userfile=" + URLEncoder.encode("/var/www/squadstats/statsigs/bg-sidewinder.png");
urlConn.setRequestProperty("Content-Length", content.length()+"" );
printout =new DataOutputStream( urlConn.getOutputStream() );
printout.writeBytes (content);
printout.flush ();
printout.close ();
}
catch (MalformedURLException me)
{
System.err.println("MalformedURLException; " + me);
}
catch (IOException ioe)
{
System.err.println("IOException; " + ioe.getMessage());
}
}
}
Please help.
Thanks

