Sorry if the title is worded badly, but I'm very new to this, and still learning. I spent about an hour googling and couldn't find the answer, so I figured I'd post my issue. I have a web server with a php script on it, and I'm trying to be able to send a post request from powershell that uploads a file, and the file will be saved to the web server. Here is the script I have right now:
<?php
$file = date("Hism") . ".txt";
file_put_contents($file, file_get_contents("php://input"));
?>
This works, but it always sets the file extension to txt, and the file name to the date. I found some things that I didn't fully understand about $_FILES["file"]["name"] but replacing the date("Hism") . ".txt" part with that gives the error:
PHP Notice: Undefined index: file in /home/ubuntu/phpServer/i.php on line 2
PHP Notice: Trying to access array offset on value of type null in /home/ubuntu/phpServer/i.php on line 2
PHP Warning: file_put_contents(): Filename cannot be empty in /home/ubuntu/phpServer/i.php on line 3
If it matters, the PowerShell script I am using to send the post request is:
iwr $ip/i.php -method POST -infile C:\test.txt