PHP使用API向PYTHON发送文件,反之亦然

2024-10-06 11:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我对API、PHP和PYTHON都是新手。我正在尝试通过API连接我的PHP和PYTHON脚本,到目前为止我尝试的是:

PHP script to choose file:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<font color="#330033">Choose a file to upload: </font>
<input id="uploadedfile" name="uploadedfile" type="file" accept="text/plain"/><br />
<input type="submit" value="Upload File" />
</form>

uploader PHP script : uploader.php :

$target_path = $_FILES['uploadedfile']['name'];

$output = shell_exec("python Demo.py $target_path $r");

That executes the python script by submiting the user chosen text file info.

Demo.py

with open(sys.argv[1]) as f: to receive the file and do the desired action.

现在我想通过API发送文件,将API调用从PHP文件添加到python脚本,python脚本应该通过API接收文件,然后通过API再次发送回来。你知道吗

我被困住了,不知道怎么继续。请帮忙。你知道吗


Tags: 文件thetoform脚本apiinputscript