Answer the question
In order to leave comments, you need to log in
Uploading photos to VK API album (empty photos_list value)?
Help what is wrong. Returns empty on save
if (isset($_POST['reload']) && $_POST['reload'] !== '') {
if (isset($rowCount2) == isset($groupId[1])) {
$allowFiles = ['jpg', 'png', 'gif', 'bmp', 'jpeg'];
$attachments = '';
$account['token'] = 'тут токен';
$account['album'] = 243088786;
$token = $account['token'];
$attachforpost = '';
// загрузка обложки
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
$ext = pathinfo($_FILES['file']['name']);
if(!isset($ext['extension'])) { $ext['extension'] = '';}
$ext = strtolower($ext['extension']);
if (!in_array($ext, $allowFiles)) {
$message = "<div class=\"callout callout-danger\">Ошибка при загрузке файла: загрузить можно только файлы с расширением jpg, png, gif, bmp, jpeg. </div>";}
elseif(!is_uploaded_file($_FILES["file"]["tmp_name"]) || !move_uploaded_file($_FILES["file"]["tmp_name"], "/tmp/{$token}_".$_FILES["file"]["name"])) {
$message = "<div class=\"callout callout-danger\"> Ошибка при загрузке файла: попробуйте еще раз. </div>";$_SESSION['token'] = $token; }
else {
$members = json_decode(file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id={$account['album']}&group_id=79668981&access_token={$account['token']}"),true);
//var_dump($members);
if (isset($members['response']['error'])) {
$message = "<div class=\"callout callout-danger\"> Ошибка при загрузке файла: Сервис недоступен, попробуйте повторить позднее. </div>";
$_SESSION['token'] = $token;
} else {
$curl = curl_init($members['response']['upload_url']);
$opts = [
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_POSTFIELDS => [
'file1' => "@/tmp/{$token}_".$_FILES["file"]["name"]
]
];
curl_setopt_array($curl, $opts);
$photoRequest = json_decode(curl_exec($curl), true);
$membeer = json_decode(file_get_contents("https://api.vk.com/method/photos.save?server={$photoRequest['server']}&photos_list={$photoRequest['photos_list']}&album_id={$account['album']}&group_id=79668981&hash={$photoRequest['hash']}&access_token={$account['token']}"),true);
//var_dump($membeer);
if (isset($request['response']['error'])) {
$message = "<div class=\"callout callout-danger\"> Ошибка при загрузке файла: Сервис недоступен, попробуйте повторить позднее. </div>";
$_SESSION['token'] = $token; }
else { $attachforpost = $membeer['response'][0]["src"];
}
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Try instead
'file1' => "@/tmp/{$token}_".$_FILES["file"]["name"]
I saw a similar question. The structure of the request is well laid out there, and curl is also used
How to upload a photo to the VK server (c ++, curl)?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question