A
A
artben2017-03-20 13:23:50
PHP
artben, 2017-03-20 13:23:50

Api vk empty response [photo] => [] what is wrong?

Failed to send a photo to the vk API gives an empty response:
stdClass Object ( [server] => 837339 [photo] => [] [hash] => f426b76a8de6b478de832b7f52b3810f )
As you can see, the photo is not loaded.
Code Here:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$uploadURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

//  Ниже заголовки и менял и удалял и документацию читал, что можно их не использовать
  // curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data; boundary=-------------573cf973d5228 charset=UTF-8']);
  
$lala = "111.png"; // С путем файла тоже и прописывал полный, и брал просто ссылку на др. фаил.
    $CURLFilee= new CURLFile($lala,'image/png','111.png');      echo	"<img src=$lala  />"; 
 curl_setopt($ch, CURLOPT_POSTFIELDS, ['photo' => $CURLFilee]);
 curl_setopt($ch, CURLOPT_POST, true);

    $json = json_decode(curl_exec($ch));
  print_r($json);

Gives the answer:
stdClass Object ( [server] => 837339 [photo] => [] [hash] => f426b76a8de6b478de832b7f52b3810f )
Let's try to pass the file to itself:
qwesting.php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://11.localhost/answer.php');

//curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data; boundary=-------------573cf973d5228']);
  
  
$CURLFilee = new CURLFile('111.png','image/jpg','111.png');
 print_r($CURLFilee);
 curl_setopt($ch, CURLOPT_POSTFIELDS,  ['photo' => $CURLFilee]);
 curl_setopt($ch, CURLOPT_POST, true);

$page = curl_exec($ch);
$sent_headers = curl_getinfo($ch, CURLINFO_HEADER_OUT);
curl_close($ch);
echo $sent_headers;

Response file:
foreach (getallheaders() as $name => $value) 
  {
  echo "$name: $value\n";
  }
  
 
print_r( $_POST );
print_r( $_FILES );
move_uploaded_file ( $_FILES['upload']['tmp_name'], 'image.jpg' );

Returns: Host: 11.localhost Accept: */* Content-Type: application/x-www-form-urlencoded Expect: 100-continue Array ( ) Array ( )
As we see the arrays are empty, what could be wrong? Already rummaged everything .. I can’t catch up myself

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-03-20
@tomnolane

Why does vk api return empty "photo":"[]" ???
Uploading photos to a VK album, what's wrong?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question