Answer the question
In order to leave comments, you need to log in
Convert from python to php 2 lines. But how?
Everything would be fine if it weren't so sad.
In general, in solving one painfully simple task, I came across what would be better and more convenient for me to write in php, but since I'm just starting the programming path, I don't understand how to rewrite this line in php.
With a post request, things are easier, but with a python dictionary, there are problems.
file = {'file1' : open('name.img', 'rb')}
ur = requests.post(upload_url, files=file).json()
Answer the question
In order to leave comments, you need to log in
<?php
$upload_url = "тут ваш upload_url";
$ch = curl_init($upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file1' => '@name.img'));
$result = curl_exec($ch);
$ur = json_decode($result);
//print_r($ur);
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
$client = new Client();
$body = fopen('/path/to/file', 'r');
$r = $client->request('POST', 'http://httpbin.org/post', ['body' => $body]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question