Answer the question
In order to leave comments, you need to log in
Why empty photos_list[] in VK API?
Hello! I can not understand why VK does not upload the image to the server. I found exactly the same problem on the toaster and there it was solved, rewrote it to myself - it didn’t work out, photos_list is empty:
$file_path = '/var/www/data/commons/img/name.jpg';
$ch = curl_init($upload_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['file1' => new CurlFile($file_path)]);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data; charset=UTF-8'));
$json = json_decode(curl_exec($ch));
curl_close($ch);
var_dump($json);
{"server":834228,"photos_list":"[]","aid":239214627,"hash":"fg95d62a0414365a0c2ae4a744e1d4c7","gid":135560236}
Answer the question
In order to leave comments, you need to log in
Solved the problem. It turned out that the pictures were crooked.
For those who encounter such a problem, the code above is working. In order to write an image (base64) to your server, you need to do this:
file_put_contents($file_path, file_get_contents($_POST['img1']));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question