2014-01-11 62 views
0

我知道如何將文件上傳到PHP腳本以將文件存儲到網絡服務器,並且PHP腳本會生成唯一的文件名。然後我想使用VB腳本中的響應,就像讀取響應一樣。我的代碼是:上傳文件並在Visual Basic 2010 Express上接收響應

的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

學習VB沒什麼問題。無論您如何看待其語法,您的A級課程都會讓您失望,因爲它沒有涵蓋支持衆多企業的語言。 – peterG

回答

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 
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 
相關問題