Answer the question
In order to leave comments, you need to log in
How to upload a photo through VK api?
Greetings.
I decided to upload files to VK.
The code :
function DoPostRequestNigga($url, $post_data){
$post_data = http_build_query($post_data); // Шифруем,для передачи на сервер
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
// указываем, что у нас POST запрос
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 1);
// добавляем переменные
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$output = curl_exec($ch);
echo __DIR__;
return $output;
curl_close($ch);
}
print_r(DoPostRequestNigga($vk->request('photos.getMessagesUploadServer')['response']['upload_url'], array('photo' => __DIR__ . '/@photo.png')));
Answer the question
In order to leave comments, you need to log in
On 5.6 it works like this.
Example for loading into the dialog:
(important, see the documentation, the photo is loaded into the dialog in the photo field, in other places it can be loaded in the file field).
$photo = 'file.png';
$postparam=array("photo"=>"@".$photo);
$ch = curl_init($request_server->response->upload_url);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postparam);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data; charset=UTF-8'));
$upload = json_decode(curl_exec($ch));
curl_close($ch);
"photo"=> new CURLFile($photo)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question