dsv38843 2019-01-23 03:17
浏览 95

Python使用Post将图像发送到服务器上的PHP脚本,图像到达但已损坏且小于应有的值

I'm attempting to use my ubuntu server to run some measurement code on an image that I can't run locally(it's a windows issue).

The local script is written in python3, which sends the image to a php script on the server.

The image does show up on the server side with the correct name but when I open it, linux mint tells me "Fatal eorror reading PNG image file: Not PNG file".

The original image is over 200 kb while the server site image received is only 40 bytes so it looks as if it's corrupted or didn't all get received.

I'm now on hour 6 trying to get this to work having looked over dozens of tutorials and similar examples here on stackoverflow. I'm willing to admit now that I must be missing something. Any help would be greatly appreciated.

If I echo "file_get_contents('php://input');" on the php server side it spits out "file=%3C_io.BufferedReader+name%3D%271.png%27%3". No sure if that helps any.

Python3 local script

import urllib.request, urllib.parse
import requests

url = 'http://165.227.207.246/returnState.php'

data = {
'file': open('1.png', 'rb')
}

opener = urllib.request.build_opener()
opener.addheaders = [('Content-Type', 'image/png')]
urllib.request.install_opener(opener)

data = bytes( urllib.parse.urlencode( data ).encode() )
handler = urllib.request.urlopen( url, data );
print( handler.read().decode( 'utf-8' ) );

PHP receiving script

file_put_contents("/var/www/html/screens/1.png", 

file_get_contents('php://input'));

#move_uploaded_file($uploadfile,'var/www/html');

var_dump($_FILES);

echo 'DONE';
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R
    • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
    • ¥15 八路抢答器设计出现故障
    • ¥15 opencv 无法读取视频
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))