我知道如何将文件上传到PHP脚本以将文件存储到Web服务器,并且PHP脚本生成唯一的文件名。我想在VB中使用PHP脚本的响应,有点像读取响应。我的代码是:
Visual Basic:
Sub uploadfile()
For Each fPath In FilePath
My.Computer.Network.UploadFile(fPath, "http://mydomain.com/upload.php")
MsgBox(fPath)
Next
End Sub
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);
}
?>
答案 0 :(得分:0)
我自己找到了解决方案:
For Each fPath In FilePath
Dim client As New WebClient()
Dim responseBinary As Byte()
responseBinary = client.UploadFile("http://example.com/upload.php", fPath)
Dim response As String
response = Encoding.UTF8.GetString(responseBinary)
MsgBox(response)
Next
答案 1 :(得分:0)
研究人员 您必须使用使用
For Each fPath In FilePath
Using client As New WebClient()
Dim responseBinary As Byte()
responseBinary = client.UploadFile("http://example.com/upload.php", fPath)
Dim response As String
response = Encoding.UTF8.GetString(responseBinary)
MsgBox(response)
End Using
Next