B
B
Bur Ov2017-01-28 16:19:18
PHP
Bur Ov, 2017-01-28 16:19:18

Uploading photos to a VK album, what's wrong?

$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  $album_id = "240785731";

    $photosgetUploadServer = by("photos.getUploadServer", "v=5.26&group_id=109792228&album_id=".$album_id."&access_token=".$token);
    $upload_url = $photosgetUploadServer["response"]["upload_url"];
    $path  = dirname(__FILE__); 
    $array = array("file1" => "@".$path."/test1.jpg" );
    $upload = curl($upload_url, $array);
    $json = json_decode($upload, 1);
    var_dump($json);
    $test = by("photos.save", "album_id=".$album_id."&hash=".$json["hash"]."&server=".$json["server"]."&photos_list=".$json["photos_list"]."&group_id=109792228&access_token=".$token);
    sleep(3);
  
  function by($method, $peremeter){ 
    return json_decode(curl("https://api.vk.com/method/".$method."?".$peremeter),1); 
  }
  
  function curl($url, $post = null){
    $ch = curl_init( $url );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417
    Firefox/3.0.3');
    if($post){
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    $response = curl_exec( $ch );
    curl_close( $ch );
    return $response;
  }

If you do var_dump($json) then you can see the photo array is empty ["photos_list"]=> string(2) "[]" what's the problem?
screenshoter.ru/s/280117/ypFf3Z

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-01-28
@burov0798

if php version is 7, try to add and put API version "v5.62"
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question