Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
For my A-Level project, I have to use VB and I am not proud of it.

Anyway, I know how to upload a file to a PHP script to store files to a webserver, and the PHP script generates a unique file name. I want to then use the response from the PHP script with VB, sort of like reading the response. My codes are:

Visual Basic:
VB
Sub uploadfile()
    For Each fPath In FilePath
        My.Computer.Network.UploadFile(fPath, "http://mydomain.com/upload.php")
        MsgBox(fPath)
    Next

End Sub


PHP:
PHP
<?php
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ($_FILES["file"]["error"] > 0){
    echo "Error";
}else{
    $newfile = uniqid("image_").".".$extension;
    move_uploaded_file($_FILES["file"]["tmp_name"], "Images/" . $newfile);
}
?>
Posted

1 solution

I eventually found a solution myself, here is the code:

VB
For Each fPath In FilePath
            Dim client As New WebClient()
            Dim responseBinary As Byte()
            responseBinary = client.UploadFile("http://mydomain.com/Upload.php", fPath)
            Dim response As String
            response = Encoding.UTF8.GetString(responseBinary)
            MsgBox(response)
Next
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900