我在将数据从客户端写入服务器端到 .xls、.php 或 .doc 文件时遇到问题。这是我的服务器端代码
amtOfFilesHeader = ""
while True:
d = connectionSocket.recv(1)
if d == '\n':
break
amtOfFilesHeader += d
amtOfFiles = int(amtOfFilesHeader.split()[-1])
while amtOfFiles > 0:
header = ""
while True:
d = connectionSocket.recv(1)
if d == '\n':
break
header += d
filesize = int(header.split()[-1])
# or search for the last space in header
# and get a substring of header as filename
filename = "".join(header.split()[1:-1])
data = ""
while filesize > 0:
chunk = connectionSocket.recv(1) # or any amount of data
filesize -= len(chunk)
data += chunk
file = open((server_side_folder+'/'+filename),'wb')
file.write(data)
file.close()
amtOfFiles-=1
我不断收到错误,例如:
IOError: [Errno 2] No such file or directory: 'server_side/test.xls'
虽然我已经打开了要写入的文件。我在代码中做错了吗?