Answer the question
In order to leave comments, you need to log in
Why is photos_list empty?
$token = 'TOKEN';
$group_id = 'GID';
$album_id = 'AID';
$v = '5.101';
$image_path = dirname(__FILE__).'/111.jpg';// путь до картинки
$post_data = array("file1" => '@'.$image_path);
// получаем урл для загрузки
$url = file_get_contents("https://api.vk.com/method/photos.getUploadServer?album_id=".$album_id."&group_id=".$group_id."&access_token=".$token."&v=".$v);
$url = json_decode($url)->response->upload_url;
//print_r($url);
// отправка post картинки
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = json_decode(curl_exec($ch),true);
//print_r($result);
// сохраняем
$safe = file_get_contents("https://api.vk.com/method/photos.save?server=".$result['server']."&photos_list=".$result['photos_list']."&album_id=".$result['aid']."&hash=".$result['hash']."&group_id=".$group_id."&access_token=".$token."&v=".$v);
$safe = json_decode($safe,true);
print_r($safe);
Answer the question
In order to leave comments, you need to log in
The link gives an error 100, one of the parameters is incorrect. Maybe the token is old, or they forgot to put a minus sign in the groupID (it seems like it should be there). I can throw off a similar code for loading, however, avatars, but the meaning is the same
Most likely because your php is newer than 2013.
https://wiki.php.net/rfc/curl-file-upload
Sending via @ has been deprecated for a long time.
https://www.php.net/manual/en/curlfile.construct.php
// Create a cURL handle
$ch = curl_init('http://example.com/upload.php');
// Create a CURLFile object
$cfile = new CURLFile('cats.jpg','image/jpeg','test_name');
// Assign POST data
$data = array('test_file' => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// Execute the handle
curl_exec($ch);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question