Run PHP script from java application?

I have a java client application and I need to run a PHP script on the server. This PHP scripts will create some words and excel files and I want to download the generated files on the client machine. Can I use some kind of url but without opening my browser? And then download the generated files from the server?

+3


source to share


1 answer


public class URLConnectionReader {
    public static void main(String[] argv) {
      try {
        URL phpUrl = new URL("http://server/myphp.php");
        URLConnection urlCon = phpUrl.openConnection();
        BufferedReader br = new BufferedReader(
                                new InputStreamReader(
                                urlCon.getInputStream()));
        String line;

        while ((line = br.readLine()) != null) 
            System.out.println(line);
        br.close();
      } catch(Exception e) {
        // handle errors here...
      }
    }
}

      

you will need to modify your php application to get some information about the results. Either the location of the file or the file in MIME.



But you will need to add more information so that we can help you.

+3


source







All Articles