通过套接字后图像大小减少6个字节

时间:2016-05-02 23:03:44

标签: php python image sockets

我试图通过套接字将照片从相机发送到PHP服务器。一切正常,但是当图像传送到服务器端时,它总是 - (5到10)字节原始图像,使图像损坏和不可接受。

发件人方:

this solution

接收方:

this is the sender side which is 54,546 bytes

对于发送方,我使用python:

enter code here

import socket   
import datetime
import json
import base64 , urllib
from cam import *


captureImage()

facechop('test_image.png')

image ='test_image.png'


print "----------------------------------------------"

try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('X.X.X.X', 20001))

client_socket.send(image)



        #print strng
    #client_socket.send(l)
    #l = img.read(1024)

print "Data send Successfully"

#print client_socket.recv(1024)
client_socket.close()


except Exception as e:
print("ERROR: "+str(e))

对于接收方,我使用PHP将图像保存到服务器:

function checkMessageRecieved()
{
    foreach ($this->changed as $key => $socket) {
        $buffer = null;

        while(socket_recv($socket, $buffer, 1024, MSG_WAITALL)) {


            $theData .=$buffer;

        }

    file_put_contents(__DIR__ . "/../photos/public/". uniqid() .".png",$theData);


        echo "The file has recieved successfully";

    }
}

0 个答案:

没有答案