U
U
urusai_wiz2017-02-27 19:47:59
PHP
urusai_wiz, 2017-02-27 19:47:59

Why does vk api return empty "photo":"[]" ???

<?php 
  if (!isset($_GET['url']))
    exit();

  $url = $_GET['url'];

  $img_src = $_FILES["photo"]["tmp_name"];
  $img_str = curl_file_create($img_src);

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_URL, $url);
  
  $data_str = array(
    'photo' => $img_str,
    'file1' => $img_str
  );

  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));

  $result = curl_exec($ch);
  curl_close($ch);

  header('Access-Control-Allow-Origin: *');
  header('Content-Type: application/json');
  echo $result;
?>

Can you tell me why empty "photo":"[]" is returned?
Did as here Why vk api returns empty "photo":"[]"? , but why it doesn't work, I seem to be missing something, but I don't understand. I also tried other options, but it didn't work ...
$_GET['url'] - stores the result - photos.getWallUploadServer

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Tom Nolane, 2017-02-27
@tomnolane

$img_src = '4.png'; 

$post_params = array(
'file1' => '@'.$img_src,
);

file_get_contents('https://api.vk.com/method/photos.getWallUploadServ...'.$access_token);
$dataArray=json_decode($data);

$ch = curl_init( $dataArray->response->upload_url );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$response = curl_exec( $ch );
curl_close( $ch );
print_r($response); 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question