php function upload_file chat_id name server json_decode vk photos get

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
function upload_file($chat_id, $q, $name) {
$server = json_decode(vk("photos.getMessagesUploadServer", ""), 1);
$url = $server["response"]["upload_url"];
if($curl = curl_init()) {
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => [
"photo" => "@".$name
]
]);
$out = curl_exec($curl);
curl_close($curl);
}
$query = json_decode($out, 1);
$up = json_decode(vk("photos.saveMessagesPhoto", [
"server" => $query["server"],
"photo" => $query["photo"],
"hash" => $query["hash"]
]), 1);
send($chat_id, $q, $up["response"][0]["id"]);
}