M
M
MMMYIWW2016-12-18 18:20:54
PHP
MMMYIWW, 2016-12-18 18:20:54

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);

In response I get:
{"server":834228,"photos_list":"[]","aid":239214627,"hash":"fg95d62a0414365a0c2ae4a744e1d4c7","gid":135560236}

UPD: so I managed to upload the image. However, another problem got out - some images, he does not want to accept (most, even) - he simply returns an empty photos_list. The pictures have a small size, some are uploaded to VK, while others are not. In what there can be a problem - I do not represent.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MMMYIWW, 2016-12-18
@MMMYIWW

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 question

Ask a Question

731 491 924 answers to any question