I am creating a machine-learning web application using PHP and here is how I send my data from PHP to Python file. So, I have created a simple PHP and Python file and sent data accordingly.
test.php
<?php
echo shell_exec("py test.py 1 2 3 ");`
?>
py: is the location of your python.exe. You can either use py or python depending on your operating system.
test.py: is the location of your python file. if both PHP and Python are in the same folder, you can write the name of the Python file here.
1 2 3: is the array of data you want to send to the Python file.
test.py
import sys
num_1 = sys.argv[1]
num_2 = sys.argv[2]
num_3 = sys.argv[3]
total = int(num_1)+int(num_2)+int(num_3)
print(total)
Hope it helps 😣
/home/pi/Python.pyhello