Why do I receive an empty response photo?

// Function API call
 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"];
}
}

 // The function save the picture to the server 
 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 for loading the image
 function curl($url, $upload = false) {
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, THIS, 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
June 8th 19 at 17:14
2 answers
June 8th 19 at 17:16
Solution
It worked like this:

$upload = curl($getWallUploadServer["upload_url"], array("file1" => new CURLFile(dirname(__FILE__)."/image.jpg")));
June 8th 19 at 17:18
You were not sent the parameter photos_list.

Like this worked for 5.4, if the error is not in php.
Change hoster for the php version, as put above 5.5 I get an error as below 5.6 and all the work and post on the wall picture.

In 5.4 and 5.5 will work fine, but with 5.6 already writing error No. 100. I read a little of php 5.6 CURLFile appears . Can be in this case?

php.net/manual/en/class.curlfile.php - ludie commented on June 8th 19 at 17:21
It needs to be addressed. But what version of IPA are you using? - Mya_Kohler commented on June 8th 19 at 17:24
Mistake to report the absence of one of the options. Specifically, there is no photos_list.

https://vk.com/dev/errors - Mya_Kohler commented on June 8th 19 at 17:27
corrected, was a mistake because you didn't see the image, this parameter was empty. - ludie commented on June 8th 19 at 17:30

Find more questions by tags PHP