F
F
fman22015-11-07 11:54:11
PHP
fman2, 2015-11-07 11:54:11

Uploading files to VK. Via VK API. What am I doing wrong?

Good afternoon!
There is a download code:

$server = $this->request('photos.getWallUploadServer', [
    'group_id'  =>  $groupId
]);

$uploadDir = $server->upload_url;

$ch = curl_init($uploadDir);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_POSTFIELDS,  ['photo' => '@'.realpath('C:/www/OpenServer/domains/srv/web/images/wall/1/12.jpg')]);
$otvet = curl_exec($ch);
curl_close($ch);
var_dump($otvet);

For some reason, the file is not loaded, the response comes:
"{"server":627922,"photo":"[]","hash":"578a004d576a5a13d20f24b3669de74a"}"
I get the Url for downloading by the method:
https://vk.com /dev/photos.getWallUploadServer I have it correct
And I upload the file using the method: Uploading photos to the user's wall
: passed user_id or group_id parameters.
2. The application generates a POST request to the received address.
The request must include the photo field containing the image file (JPG, PNG,

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question