I am trying to HTTP push files to a server from Powershell on my Windows machine. The server is using a PHP script (cut down from the w3schools version here: https://www.w3schools.com/php/php_file_upload.asp):
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Using the HTML file shown on the w3schools tutorial and Chrome as a browser, I am able to upload using this script with no problems. However, I can't seem to upload using Invoke-WebRequest.
Here is the command I am using:
Invoke-WebRequest -InFile "C:\test.txt" -ContentType "text/plain" -Method post -Uri http://example.com/upload/upload.php
And a segment of the output:
StatusCode : 200
StatusDescription : OK
Content : Sorry, there was an error uploading your file.
What am I doing wrong?