Answer the question
In order to leave comments, you need to log in
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);
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
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question