require_once('vk-class.php' );
$proxy_path = '/ph/index.php'; //путь к прокси
function vkh_download_mp3($song_id) { //в $song_id передается id песни вида ownerid_songid
$api_id = get_vk_params('api_id');
$secret_key = get_vk_params('api_key');
$token = get_vk_params('token');
$mid_arr = explode('_', $song_id);
$owner_id = $mid_arr[0];
$mid = $mid_arr[1];
$VK = new vkapi($api_id, $secret_key, 'api.vk.com/method', $token);
$type = 'audio_ids';
$song_arr = $VK->api('audio.get', array('owner_id'=>$owner_id, $type=>$mid));
$out = array();
foreach($song_arr['response']['items'] as $song)
{
$song['name'] = $song['artist'].' - '.$song['title'].'.mp3'; //формируем название файла
$song['oid'] = $owner_id.'_'.$song['id'];
$song_pre_arr = explode('?',str_replace(array('http://', 'https://'), array('',''), $song['url']));
$song_pre = $song_pre_arr[0];
$song['url'] = site_url().$proxy_path.'?q='.$song_pre;
$out[] = $song;
}
return $out;
}
//echo 'ok';
if(isset($_REQUEST['song_id']) && $_REQUEST['song_id'] != '')
{
$song_arr = vkh_download_mp3($_REQUEST['song_id']);
$furl = $song_arr[0]['url'];
//echo $furl.'--';
$fname = $song_arr[0]['name'];
$Headers = @get_headers($furl);
if(strstr($Headers[0], '200')) {
//echo 'ok';
header('Content-Description: File Transfer');
header('Content-Type: audio/mpeg');
header('Content-Disposition: attachment; filename="'.$fname.'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header($Headers[11]);
ob_clean();
flush();
readfile($furl);
exit;
}
}