python - 如何将使用 php 上传的图像发送到 python 脚本进行处理?
问题描述
我想使用 php 上传图像并在 python 脚本中使用上传的图像,这样 python 脚本应该能够自动获取这个存储的图像。我应该在 python 脚本中写什么?
这是上传图片的php部分:
<form action="upload.php" method="POST" enctype="multipart/form-data">
<label for="file">Select image:</label>
<input type="file" id="file" name="file" required><br><br>
<button type="submit" name="submit"> Upload Image </button>
</form>
这将创建图像的本地存储:
<?php
if(isset($_POST['submit']))
{
$file = $_FILES['file'];
$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];
$fileExt = explode('.',$fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg','jpeg','png');
if(in_array($fileActualExt, $allowed))
{
if($fileError === 0)
{
if($fileSize<1000000)
{
$fileNameNew = 'uploaded_image'.".".$fileActualExt;
$fileDestination = 'uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName,$fileDestination);
$output = shell_exec("python3 /var/www/html/py_script.py $fileNameNew");
echo "uploaded successfully";
}
else
{
echo "File size exceeded!";
}
}
else
{
echo "There was an error uploading your file!";
}
}
else
{
echo "You cannot upload files of this type!";
}
}
我应该在 python 脚本中写什么来自动输入这个图像?
解决方案
推荐阅读
- java - 使用 Java BufferedReader 从我的日志文件中过滤掉某些数据的最有效方法
- excel - Excel + VBA 与货币格式之间的精度问题
- javascript - 通过 window.location.href 获取文件时我的加载程序无法正常工作
- c# - 模型绑定失败时的自定义响应 ASP.NET Core API
- python - Ubuntu:QXcbConnection:无法连接到显示器无法连接到任何 X 显示器
- delphi - 如何在delphi运行时将charteries添加到dbchart
- swift - 如何在没有 microsoft azure 用户的情况下使用 swift 获取访问令牌?
- python - Python 打印字典的部分内容
- javascript - 根据选定的“li”类将“name”属性添加到“select”标签
- machine-learning - 多项朴素贝叶斯分类问题,需要归一化吗?