使用HTTP POST方法将图像从raspberrypi(python)发送到Web服务器后端(php)
提前道歉,我只是这个领域的初学者 我正在尝试向服务器发送图片。。。 服务器是PHP后端,设备是raspberry pi,linux操作系统使用python语言 我为这项任务做了大量研究并尝试了大量代码 服务器端php脚本是使用HTTP POST方法将图像从raspberrypi(python)发送到Web服务器后端(php),python,php,post,upload,raspberry-pi,Python,Php,Post,Upload,Raspberry Pi,提前道歉,我只是这个领域的初学者 我正在尝试向服务器发送图片。。。 服务器是PHP后端,设备是raspberry pi,linux操作系统使用python语言 我为这项任务做了大量研究并尝试了大量代码 服务器端php脚本是 <?php //if (isset($_POST['submit'])) { //echo "Success"; $file = $_FILES['file']; print_r($file); $
<?php
//if (isset($_POST['submit'])) {
//echo "Success";
$file = $_FILES['file'];
print_r($file);
$file_name = $_FILES['file']['name'];
$filetmpname = $_FILES['file']['tmp_name'];
$filesize = $_FILES['file']['size'];
$fileerror = $_FILES['file']['error'];
$filetype = $_FILES['file']['type'];
$fileExt = explode('.', $file_name);
$fileActualExt = strtolower(end($fileExt));
//$allowed = array('jpg','jpeg','png', 'pdf','docx');
//if (in_array($fileActualExt, $allowed)) {
if ($fileerror === 0) {
if ($filesize <1000000) {
$filenewname = uniqid('', true).".".$fileActualExt;
$fileDestination = 'pictures/'.$file_name;
move_uploaded_file($filetmpname, $fileDestination);
header("Location: upload_test.php?success");
}else{
echo "File size too big!";
}
}else{
echo "Error while uploading your file!";
}
//}
//}
?>
及
和
import requests
url = "http://*******.msahosting.net/upload.php"
files = {'files': open('/home/pi/im.jpg', 'rb')}
headers = {
'content-type': "multipart/form-data"
# 'accept': "application/json",
# 'apikey': "API0KEY0"
}
response = requests.post(url, data=files, headers=headers)
print(response)
但他们都没有工作
它们都返回错误代码200,表示没有错误,
虽然当我检查response.text时,我在linux终端窗口中会看到类似的内容
此网站需要Javascript才能工作,请在浏览器中启用Javascript或使用支持Javascript的浏览器
但因为这里我不使用任何浏览器,所以我尝试从我的raspberry pi上传图像
除此之外,错误代码是200,但服务器目录中没有上传文件
我尝试将“文件”更改为“图像”。。。
正在更改目录url。。。
从昨天早上开始就有很多东西,但是运气不好
有人能帮我找出问题所在,或者正确或更好的方法来完成上述任务吗
谢谢你阅读
致意
import requests
url='http://*******.msahosting.net/pictures/'
#url = 'http://*******.msahosting.net/upload.php' #tried both
data = {'submit':'submit','upload':''}
files = {'file':('im.jpg', open('/home/pi/im.jpg', 'rb'), 'image/jpeg')}
r = requests.post(url, data=data, files=files)
print(r)
import requests
url = "http://*******.msahosting.net/upload.php"
files = {'files': open('/home/pi/im.jpg', 'rb')}
headers = {
'content-type': "multipart/form-data"
# 'accept': "application/json",
# 'apikey': "API0KEY0"
}
response = requests.post(url, data=files, headers=headers)
print(response)