receive output from java DataOutputStream in a php page

I have a java applet which I am using to send a file back to my server with – on the server end I want to receive this on a php page.

Below is the java code which is doing the sending, on the php side of things I have checked the global arrays and I have the data passed by the URL, but not the file data. I have really searched and scratched on this one so any help appreciated.

String strURL = sendToURL + "?ACTION=POST&LEN=" + imgBytes.length + "&Fname=picture.png";
        URL urlServlet = new URL(strURL);
        URLConnection sCon = urlServlet.openConnection();
        if (sCon.getAllowUserInteraction()) {
        sCon.setRequestProperty("Content-Type", "text/html");
        sCon.setRequestProperty("Connection", "Keep-Alive");
        DataOutputStream out = new DataOutputStream(sCon.getOutputStream());

        int index = 0;
        size = 1024;
        do {
            if (index + size > imgBytes.length) {
                size = imgBytes.length - index;
            out.write(imgBytes, index, size);
            index += size;
        } while (index < imgBytes.length);


SOLVED – as so often happens one posts a question after days of battling and mere minutes later a solution presents.

I got thinking after the comment about using SOAP that I remembered using cURL for transferring XML data once before. a few searches later and I came across a much simpler and very elegant solution.

basically you can access the PUT data in php by using


so now it works awesomely

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

One Response to receive output from java DataOutputStream in a php page

  1. Dukeatcoding says:

    i used a lot of times Soap Messages to get Data From PHP to Java that works fine

    So Use PHP as Webservice and Communicate via SOAP

    Setup a WSDL File

    Generate Java Stubs and Skeletons

    Load WSDL into a php skript

       $soapClient = new SoapClient("blahblah.wsdl"); 

    And do your logic in the php

    Then use the Java Stubs to call the server and transmit your data

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>