I'm trying to write a tool to batch upload images to my website, but I'm having trouble receiving (or sending) the actual data to the server.
I'll start with some C# code as it should explain what I'm trying to do better that I can articulate:
private bool Upload( string LocalFile, int ItemID, string Description, DateTime Date, string Photographer )
{
WebClient oWeb = new System.Net.WebClient();
NameValueCollection parameters = new NameValueCollection();
parameters.Add( "Type", "1" );
parameters.Add( "ID", ItemID.ToString() );
parameters.Add( "Desc", Description );
parameters.Add( "Date", Date.ToString( "yyyy-MM-dd" ) );
parameters.Add( "Photographer", Photographer );
oWeb.QueryString = parameters;
var responseBytes = oWeb.UploadFile( "http://www.teamdefiant.co.uk/moveuploadedfile.php", LocalFile );
string response = Encoding.ASCII.GetString(responseBytes);
MessageBox.Show( "Response: \n\n" + response + "\n\nPost Data: \n\n" + LocalFile + "\n" + ItemID.ToString() + "\n" + Description + "\n" + Date.ToString("yyyy-MM-dd") + "\n" + Photographer );
Clipboard.SetText( "Response: \n\n" + response + "\n\nPost Data: \n\n" + LocalFile + "\n" + ItemID.ToString() + "\n" + Description + "\n" + Date.ToString("yyyy-MM-dd") + "\n" + Photographer );
return true;
}
When I receive the response, (as displayed in the MessageBox, and Clipboard.SetText) I get the following data:
Response:
Upload:
Type:
Size: 0kb
Stored in:
Post Data:
C:\Users\<MyFolder>\Pictures\Website\ExampleImage.png
4
Picture Description
2014-12-10
Photographer
And for completeness, here's the php code:
<?PHP
if ($_FILES["myfile"]["error"] > 0)
{
echo "Error: " . $_FILES["myfile"]["error"] . "\n";
}
else
{
echo "Upload: " . $_FILES["myfile"]["name"] . "\n";
echo "Type: " . $_FILES["myfile"]["type"] . "\n";
echo "Size: " . ($_FILES["myfile"]["size"] / 1024) . " Kb\n";
echo "Stored in: " . $_FILES["myfile"]["tmp_name"] . " \n";
echo $_POST["Type"] . " \n";
echo $_POST["ID"] . " \n";
echo $_POST["Desc"] . " \n";
echo $_POST["Date"] . " \n";
echo $_POST["Photographer"] . " \n";
}
?>
I've tried searching for answers but haven't been able to find a working solution that I can understand. (I'm still just learning C#.)
I don't get any code errors in Visual Studio, not do I get any POST errors server side, so I'm stumped.
Any and all help is appreciated!
EDIT
I tried visiting the webpage directly and get the same response, so it looks like no data is being sent to the server?? :(