简体   繁体   中英

Passing filename from Java to PHP using HTTP URL

I want to upload my file from Java using SFTP and upload the file path with PHP script but the problem is I am not getting the path in my PHP script say in a textbox but in my IDE the path is showing

Uploading directly using SFTP is fine but the path of the file is not displaying in my PHP textbox*

JAVA code

BufferedReader in;
boolean blResult = sftpBean.connect("xx.xxx.xx.x", xx, "xxxx", "xxxx");
if (blResult) {
    System.out.println("Successfull Connection");
    String path="/home/folder/upload/";
    String p="http://xx.xxx.xx.x/upload/";
    blResult = sftpBean.uploadFile(data,result,path);           
    if(blResult) {
        OutputStream os = null;
        InputStream is = null;
        URL url = new URL("http://xx.xxx.xx.x/folder/test.php?test="+p+result); 
        URLConnection conn = url.openConnection();
        conn.connect();                          
        in = new BufferedReader(newInputStreamReader(conn.getInputStream())); 
        String inputLine;         
        while((inputLine = in.readLine()) != null) {
            System.out.println(inputLine);
        }
        in.close();

PHP CODE test.php

<?php
    $path=$_GET['test'];
    echo "<input type='text' value='$path'>";
?>

The expected result would be the path name will display in my php textbox So far the results display only in my IDE

You should encode your query parameters.

String testParameterEncoded = URLEncoder.encode(p + result, StandardCharsets.UTF_8);
URL url = new URL("http://xx.xxx.xx.x/folder/test.php?test=" + testParameterEncoded);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM