Marija Todorović
Marija Todorović

Reputation: 43

Run php script from java application?

I have java client application and I need to run a PHP script on server. That PHP scrips will create some word and excel files and than I want to download that created files on client's machine. Can I use somehow URL, but without opening a browser? And then download created files from server?

Upvotes: 3

Views: 3630

Answers (1)

MrSimpleMind
MrSimpleMind

Reputation: 8587

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 the php applicatin to receive some details about the results. Either the file location or maybe the file in MIME.

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

Upvotes: 3

Related Questions