Various r ... I'll write it down because it seems to be useful for interesting things
pic_post.py
import requests
#This sender → put it locally
with open("img.jpg ", "rb") as f:#Open image(Like reading?)To do
url='http://hogehoge.jp/pic_save.php'#Destination
r = requests.post(url, f.read())#Send
pic_save.php
<?php
//This is on the receiving side → on the server side
$bin = file_get_contents("php://input");//Take out the received item
file_put_contents('./img.jpg',$bin);//In the same directory, "img.Save with the file name "jpg"
?>
For the time being, it should work with the above code I may add what the meaning of f.read () is If the extension is different (png, gif) or if you want to select an image, you really want to think about it
[PHP] Download the image and save it in a specific directory on the server http://codaholic.org/?p=341
Recommended Posts