天天看點

Python 上傳圖檔檔案

'''
uploadImgFile by 鄭瑞國
'''
import requests
  
url = 'http://192.168.13.112/share/upload.php'
#url = 'http://www.test.com/doPost.php'
#files = {'file': open('D:/tmp/1.jpg', 'rb')}
 
# 要上傳的檔案
files = {'file123': ('1.jpg', open('D:/tmp/1.jpg', 'rb'))
        }     #顯式的設定檔案名
             
# post攜帶的資料           
data = {'a':'楊','b':'hello'}
 
  
r = requests.post(url, files=files, data = data)
print(r.text)