sbondo1234
Member
- Joined
- Jan 21, 2020
- Messages
- 8
- Programming Experience
- 1-3
I have a C# script that uploads an image to my webserver with PHP here:
C#:
PHP:
This all works, but I also want to send along a variable that can be accessed in the PHP code like this:
I want to send all of this in one request because the path the file ends up in is going to be decided by the C# and sent as 'variable' in the last PHP example.
C#:
C#:
WebClient Client = new WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("https://example.com/test.php", "POST", @"C:\mario.jpg");
string s = Encoding.UTF8.GetString(result, 0, result.Length);
PHP:
PHP:
$uploads_dir = 'img'; //Directory to save the file that comes from client application.
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
This all works, but I also want to send along a variable that can be accessed in the PHP code like this:
PHP:
$variable = $_POST['variable'];
I want to send all of this in one request because the path the file ends up in is going to be decided by the C# and sent as 'variable' in the last PHP example.