R
R
rusgayfer2018-01-31 21:52:36
PHP
rusgayfer, 2018-01-31 21:52:36

Why is the empty response photo coming?

// Функция вызова API
  function by($method, $array = false) {
    $response = curl("https://api.vk.com/method/".$method, $array);
    $json = json_decode($response, true);
    if($json["error"]["error_msg"]) {
      return $json["error"];
    } else {
      return $json["response"];
    }
  }
  
    // Функция сохранения картинки на сервер	
      function download($picture = null, $group = null) {
    global $token, $group_post;
    $pic = curl_init($picture);
    $file = fopen("tools/image.jpg", "wb");
    curl_setopt($pic, CURLOPT_FILE, $file);
    curl_setopt($pic, CURLOPT_HEADER, 0);
    curl_exec($pic);
    curl_close($pic);
    $getWallUploadServer = by("photos.getWallUploadServer", array("group_id" => $group_post, "access_token" => $token));
    $upload = curl($getWallUploadServer["upload_url"], array("file1" => "@".dirname(__FILE__)."/image.jpg"));
    $json = json_decode($upload, true);
    //print_r($json);
    $saveWallPhoto = by("photos.saveWallPhoto", array("group_id" => $group_post, "photo" => $json["photo"], "hash" => $json["hash"], "server" => $json["server"], "access_token" => $token));
    print_r($saveWallPhoto);
    return $saveWallPhoto[0]["id"];
  }

  // Функция загрузки изображения
  function curl($url, $upload = false) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 AlexaToolbar/alxg-3.1');
    if ($upload) { 
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $upload);
    }
    $response = curl_exec($ch);
    curl_close($ch);
    //print_r($response);
    return $response;
  }

Array
(
    [error_code] => 100
    [error_msg] => One of the parameters specified was missing or invalid: photos_list is invalid
    [request_params] => Array
        (
            [0] => Array
                (
                    [key] => oauth
                    [value] => 1
                )

            [1] => Array
                (
                    [key] => method
                    [value] => photos.saveWallPhoto
                )

            [2] => Array
                (
                    [key] => group_id
                    [value] => 71359952
                )

            [3] => Array
                (
                    [key] => photo
                    [value] => []
                )

            [4] => Array
                (
                    [key] => hash
                    [value] => 9e0c8da37b6dd9c2e1a91d5f245ae58e
                )

            [5] => Array
                (
                    [key] => server
                    [value] => 840629
                )

        )

)

Gives such a picture does not see php 7.0. And when I put php 5.4,5.5 everything works

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rusgayfer, 2018-01-31
@rusgayfer

It worked like this:

$upload = curl($getWallUploadServer["upload_url"], array("file1" => new CURLFile(dirname(__FILE__)."/image.jpg")));

A
Alibek Issakul, 2018-01-31
@Alibek-kz

You didn't send the photos_list parameter there.
How did it work on 5.4 if the error is not in php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question