I had an opportunity to upload files to a server, so this is a memo of the process.
The image receiving program running on the server was created in PHP. Please be careful about security.
upload.php
<?php
$root = "./"; // Change as appropriate.
$path = $_POST["path"];
$dirname = dirname($path);
if (!file_exists($dirname)) {
mkdir($dirname, 0755, true);
}
move_uploaded_file($_FILES['media']['tmp_name'], $root.$path);
?>
The program to upload files via POST was created in Python. It posts the local image file and the output destination path.
import requests
import json
url = '<URL of upload.php>'
input_local_image_path = 'input/test.jpg'
output_server_image_path = "output/test2.jpg"
files = {'media': open(input_local_image_path, 'rb')}
json_data = {
"path": output_server_image_path
}
response = requests.post(url, files=files, data=json_data)
print(response)
print(response.text)
Again, please ensure you give sufficient consideration to security before use.