A
A
Ainur Shakirov2017-03-15 12:01:06
PHP
Ainur Shakirov, 2017-03-15 12:01:06

I can't upload a document via VK API, what's wrong?

Code (tried a bunch of options):

$url=file_get_contents('https://api.vk.com/method/docs.getWallUploadServer?group_id='.gid().'&access_token='.token2().'&v=5.60');
$url = json_decode($url); 
$url=$url->response->upload_url;

  $post = array('file'=> "@ta.mp3"));
 
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
  curl_setopt($ch, CURLOPT_URL, $url); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
  $output = curl_exec($ch);

{"error":"unknown error"}And I got nothing but nothing in return .
The download url is correct. The token has access.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-03-15
@BuriK666

php.net/manual/ru/function.curl-setopt.php
All data sent in an HTTP POST request. To transfer a file, precede the file name with @ and also use the full path to the file.

As of PHP 5.5.0, the @ prefix is ​​deprecated and files can be uploaded using CURLFile . The @ prefix can be disabled to allow values ​​that begin with @ to be passed by setting the CURLOPT_SAFE_UPLOAD option to TRUE.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question