Answer the question
In order to leave comments, you need to log in
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);
$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;
foreach (getallheaders() as $name => $value)
{
echo "$name: $value\n";
}
print_r( $_POST );
print_r( $_FILES );
move_uploaded_file ( $_FILES['upload']['tmp_name'], 'image.jpg' );
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question