pass post params to WebClient.UploadFileAsync

2019-05-31 11:37发布

问题:

hello i have a simple file upload with just one extra post parameter which is imgtitle.
it's used to rename the image after it's been transferred to the upload location on the server.
PHP:

<?php   
    $imgtitle = $_POST['title'];

    $current_image=$_FILES['file']['name'];
    $extension = substr(strrchr($current_image, '.'), 1);
    $new_image = $imgtitle. "." . $extension;
    $destination="uploads/".$new_image;
    $action = copy($_FILES['file']['tmp_name'], $destination);

    echo "--".$imgtitle."--";
?>

the upload works fine here.
http://tnsatchat.heliohost.org/tnsatchat/upload/upload.html
/upload/uploads/abcd.jpg

what i want to do is make a simple vb.net app which would allow me to upload the file/image
i'm using WebClient to do so.
but i'm having some difficulties passing the imgtitle parameter. here's my code

Dim ur = New Uri("http://tnsatchat.heliohost.org/tnsatchat/upload/upload.php?title=testname")
wc.UploadFileAsync(ur, "POST", "C:\testimage.jpg")

the upload is working i.e the file is there .. but with an empty name !!
/upload/uploads/.jpg
".jpg" is supposed to be "testname.jpg" but i guess the PHP is not getting that parameter.
any hints please !
edit:
i used the QueryString property

Dim ur = New Uri("http://tnsatchat.heliohost.org/tnsatchat/upload/upload.php")
Dim col = New Collections.Specialized.NameValueCollection
col.Add("title", "testname")
wc.QueryString = col
wc.UploadFileAsync(ur, "POST", "C:\testimage.jpg")

but with no better luck !!