-
-
Save agoalofalife/981276482efcd98066162209ef63c3ed to your computer and use it in GitHub Desktop.
Curl отправки фото в vk api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = $_POST['upload_url']; | |
$file = new CURLFile(realpath('photo.jpg')); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, array( | |
'photo' => $file | |
)); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
echo $data; | |
//////////////////////////////////////////// | |
Отпрака на стороне клиента | |
////////////////////////////////////////// | |
/* | |
* message - сообщение, которое будет опубликовано | |
* image - картинка для постинга | |
* user_id - id текущего пользователя (к нему будет осуществлён постинг) | |
*/ | |
function wallPost(message, image, user_id) { | |
VK.api('photos.getWallUploadServer', { | |
uid: user_id | |
}, function (data) { | |
if (data.response) { | |
$.post('/upload/', { // url на ВАШЕМ сервере, который будет загружать изображение на сервер контакта (upload_url) | |
upload_url: data.response.upload_url, | |
image: image, | |
}, function (json) { | |
VK.api("photos.saveWallPhoto", { | |
server: json.server, | |
photo: json.photo, | |
hash: json.hash, | |
uid: user_id | |
}, function (data) { | |
VK.api('wall.post', { | |
message: message, | |
attachments: data.response['0'].id | |
}); | |
}); | |
}, 'json'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment