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';