I am posting a text file from python script to PHP from where I want to store them in a directory. here is my python code from where i am posting file
import requests
url = 'http://localhost:80/project/php/files.php'
file_path = 'C:\\wamp64\\www\\project\\python\\New folder\\directory_listing.txt'
with open(file_path, 'rb') as file:
files = {'file': file}
headers = {'Content-Type': 'multipart/form-data'}
response = requests.post(url, files=files, headers=headers)
print(response.text)
below is my php code which is receiving the file and then moving it to specified folder
<?php
$target_dir = "files_list/";
if (isset($_FILES["file"])) {
$target_file = $target_dir . basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "The file " . basename($_FILES["file"]["name"]) . " has been uploaded and moved.";
} else {
echo "Error uploading file.";
}
} else {
echo "No file uploaded.";
}
?>
my issue is when i run my code i get No file uploaded. as output. I have already verified all path and filenames these all are ok. I don't know why my file is not receiving at php side.If anyone has any idea kindly guide me what is wrong.