-
Java send Image to php??
I have this code in my image.java :
Code:
//... other not usefull code for this question.
public void saveImageToOutputStream(Image image, OutputStream out) {
int type = BufferedImage.TYPE_INT_RGB;
BufferedImage bimg = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics g = bimg.getGraphics();
g.drawImage(image, 0, 0, null);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bimg, "JPG", baos);
byte[] bytesOut = baos.toByteArray();
URL u = new URL("http://localhost/image/handle.php");
HttpURLConnection outt = (HttpURLConnection) u.openConnection();
outt.setRequestMethod("POST");
outt.setDoOutput(true);
outt.setDoInput(true);
outt.setRequestProperty("Content-Type", "image/png");
//outt.setRequestProperty("Content-Length", Integer.toString(out.length));
outt.connect();
OutputStream outs = outt.getOutputStream();
outs.write(bytesOut);
outs.flush();
outs.close();
textField1.setText("Done!");
} catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
}
//..rest of code is not usefull for question
I've create a .class file called image.class and I have put that into a signed jar called java
This code in my php file handle.php :
Code:
$handle = fopen('php://input','r');
while(!feof($handle)){
$data.=fread($handle, 8192);
}
fclose($handle);
$write = fopen("uploaded_picture465.jpeg", 'w');
fwrite($write, $data);
fclose($write);
And eventually I got this code in the index.html :
Code:
<html>
<head>
<title>server-Applet</title>
</head>
<body>
<applet code="image" archive="image.jar" width="529" height="50">
</applet>
</applet>
</body>
</html>
So I have the image.jar handle.php and the index.html on my server, I go to the index.html page and the image.jar is running without complications. It does set the textfield to Done! but it doesn't create the image.
I don't know where the problem is, (in the java to php part or the php to server part). So someone knows?
PS I use a local server: http://localhost/image/
-
Does this code is correct? Would it send a bufferedImage to php?
Or does the problem lies at the php code?