Python3 uploads files to the php service interface?

python Code

import requests

url = "http://xxxx.cn/file"
files = {"file":open("demo.png", "rb")}
r = requests.post(url, files=files)
print(r.text)

php Code

<?php
    public function upload(Request $request)
    {
        $file = $request->file("file");
        Log::info(json_encode($file));
    }
?>        

returned data

local.INFO: {} 

ask the Great God for an answer?

Mar.20,2022

file? Files?


check to see if the file has been received first

dd($request->file());

check the python code without


because of the limited size of files uploaded by php, small files can be uploaded successfully.

clipboard.png

Menu