I am trying to upload a file directly to the server using "curl" instead of using HTML submit form. I have the below php code on the server:
upload.php
<?php
$uldir = '/tmp/repos/';
$ulfile = $uldir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $ulfile)) {
echo "Uploaded successfully.\n";
} else {
echo "Could not upload file!\n";
}
?>
I could make it work if I use HTML form to submit and call the php, but then I want to do something similar to CGI where I can directly post the file. I use this curl command, but I get internal error from server:
curl -XPOST -T /tmp/image.png https://web-server-host/upload.php
This is usually possible with CGI, is it with PHP?
Note: this is not intended to be production config, its a test server, w.r.t security.