S
S
serg442017-03-29 17:49:19
PHP
serg44, 2017-03-29 17:49:19

How to upload images for vk.com via api?

You need to upload an image for Products on Vkontakte. I get the download address using the https://vk.com/dev/photos.saveMarketPhoto method. After, the code below should upload the image, but I get the error ERR_UPLOAD_BAD_IMAGE_SIZE: market photo min size 400x400 Tried different images.

$file["file"] = file_get_contents($image_path);
$ch = curl_init($urlUpload);
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_POSTFIELDS, $file);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$upload_data = json_decode(curl_exec($ch), true);

Answer
Array
(
    [error] => ERR_UPLOAD_BAD_IMAGE_SIZE: market photo min size 400x400
    [bwact] => do_add
    [server] => 638423
    [_sig] => 488b98bab6f2b936b568101b1997cb83
)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
serg44, 2017-03-30
@serg44

Found a solution. Working code:

$image_path = dirname(__FILE__).'/temp.jpg';
$cfile = curl_file_create($image_path,'image/jpeg','temp.jpg');
$ch = curl_init($urlImage);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => $cfile));
$result = json_decode(curl_exec($ch), true);
curl_close($ch);

P
Pavel, 2017-03-29
@PavelFokeev

curl_setopt($ch, CURLOPT_POSTFIELDS, array('file'=>'@'.$image_path));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question