I do not know how it happened, but I can not transfer the picture to the VK server. Here is the actual request:

$ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 90); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url);//тут урл, взятый с запроса photos.getUploadServer curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, array("file1" => '@'.urlencode($caption).';type=image/png')); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); $ans = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); 

All data is photo_list in response, except for photo_list , which is [] . The info shows that the file does not transfer - Upload_Content_Length - 23.

But why, I can not understand. Please help. Thank you in advance!

PS Changed Content-type to multipart , sent with and without @ , sent with urlencode and without, c ';type=image/png' and without.

I also tried POSTFIELDS to do this:

'file1=@'.urlencode($caption).'; type=image/png' 'file1=@'.urlencode($caption).'; type=image/png' , again with different parameters.

$caption contains the full path to the file (on the computer), the path is taken from the folder scanning function, plus I displayed the postfields, there can be no errors here.

  • What version of php? - zenden2k
  • PS Changed Content-type to multipart, sent with and without @, sent with urlencode and without, c '; type = image / png' and without. - Andrei Tsapenko
  • one
    To download the file must be Content-Type: multipart/form-data . clean urlencode . - zenden2k
  • Remove the line curl_setopt($ch, CURLOPT_HTTPHEADER, - zenden2k
  • Version 5.3.8, there is no possibility to upgrade, so do not offer. - Andrei Tsapenko

2 answers 2

You can translate a picture in BASE64 and send text

  • No, API VC does not accept Base64. - Andrei Tsapenko
 curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0);