Results 1 to 2 of 2
  1. #1
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Question Java send Image to php??

    I have this code in my image.java :
    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 :
    Java 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 :
    Java 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/
    Last edited by dudejonne; 11-03-2009 at 05:43 PM.

  2. #2
    dudejonne is offline Member
    Join Date
    Oct 2009
    Posts
    56
    Rep Power
    0

    Default

    Does this code is correct? Would it send a bufferedImage to php?
    Or does the problem lies at the php code?

Similar Threads

  1. Print image and send additional PCL instructions.
    By bronai in forum Advanced Java
    Replies: 1
    Last Post: 05-16-2011, 07:18 PM
  2. Replies: 1
    Last Post: 10-07-2009, 04:42 PM
  3. how to send SMS using Java API
    By sanjeevtarar in forum Advanced Java
    Replies: 4
    Last Post: 09-13-2009, 03:15 PM
  4. How to send SMS using JAVA
    By sivaskgr in forum New To Java
    Replies: 0
    Last Post: 03-18-2009, 01:37 PM
  5. Server socket - send image to client
    By Hinty in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 07:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •