основной файл:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://vkontakte.ru/js/api/xd_connection.js?2" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
VK.init(function()
{
VK.api('wall.getPhotoUploadServer', {}, function (data)
{
if (data.response)
{
$.post(
'uploadimage.php',
{upload_url:data.response.upload_url},
function (json)
{
VK.api("wall.savePost", { wall_id: "ЮИД", server: json.server, photo:json.photo, hash: json.hash, post_id:"123", photo_id:data.id , message: 'текст' }, function(data)
{
VK.callMethod("saveWallPost", data.response.post_hash);
});
}, 'json');
}
});
});
</script>
</head>
<body>
</body>
</html>
uploadimage.php:
<?php
if (isset($_POST["upload_url"])) {
define('BASEPATH', str_replace('\\', '/', dirname(__FILE__)) . '/');
$upload_url = $_POST["upload_url"];
$post_params['photo'] = '@'.BASEPATH.'additem.jpg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result);
$mess = array (server => $result->server, photo=> $result->photo, hash => $result->hash);
echo json_encode($mess);
}
?>