<?php
error_reporting (0);
set_time_limit(0);
include "config/config.php";



  $a=($_GET['a'] );
  $b=($_GET['b'] );
  $x=($_GET['x'] );
  $y=($_GET['y'] );
  $name=totranslit(clean_text($_GET['g']));
  if($_GET['g']=="play") $player=true; else $player=false;
  $name=''.$name.'.mp3';
   


$sig_vk = md5(
  $akk_on['vk_id'].'api_id='.$akk_on['api_id'].'audios='.$b.'_'.$a.'method=audio.getByIdtest_mode=1v=3.0'.$akk_on['vk_key']
);


//////////// ÌÓÒÊÀ ÑÎ ÂÐÅÌÅÍÍÛÌÈ ÔÀÉËÀÌÈ, ÇÀÏÈÑÜ ÌÀÑÑÈÂÀ ÂÛÂÎÄÀ ÂÎ ÂÐÅÌÅÍÍÛÉ ÔÀÉË
  if($full_list[sscache]=="true")
  {
  $tmpfname=md5($a."_".$b);
     if(is_file("cache/".$tmpfname.".txt"))
     {
     $xml_response=file_get_contents("cache/".$tmpfname.".txt");
     }
     else
     {
//Äåëàåì POST-çàïðîñ ê API, ïåðåäàâàÿ ïîäãîòîâëåííûå ïàðàìåòðû
$xml_response = Send_Post(
  'http://api.vkontakte.ru/api.php', 
  'api_id='.$akk_on['api_id'].'&audios='.$b.'_'.$a.'&method=audio.getById&test_mode=1&v=3.0&sig='.$sig_vk, 
  'http://vkontakte.ru/app'.$akk_on['api_id'].'_'.$akk_on['api_id'].''
);
     }
  } else
$xml_response = Send_Post(
  'http://api.vkontakte.ru/api.php', 
  'api_id='.$akk_on['api_id'].'&audios='.$b.'_'.$a.'&method=audio.getById&test_mode=1&v=3.0&sig='.$sig_vk, 
  'http://vkontakte.ru/app'.$akk_on['api_id'].'_'.$akk_on['api_id'].''
);
//////////////////////////////////////////////////////////////////FIVEM

  $parse = @simplexml_load_string(trim(ltrim($xml_response)));
if(isset($parse->audio->url))$file=$parse->audio->url;
else if($parse->url[0]) $file=$parse->url[0];
else if($parse->url) $file=$parse->url;

  $file_size=remote_filesize($file);
  
  if ($file_size[size]>0){
	
  if($full_list[sscache]=="true"){

			$fpt=fopen("cache/".md5($a."_".$b).".txt", w);
			fputs($fpt,$xml_response);
			fclose($fpt);
  }
  header("Content-Disposition: attachment; filename=" . ($name));  
  
  header("Content-Type: application/force-download");
  header("Content-Type: application/octet-stream");
  header("Content-Type: application/download");
  header("Content-Description: File Transfer");             

//header("Content-Description: File Transfer\r\n");
header("Content-Length: ".$file_size[size]."\r\n");
  
  flush();
  
  $ch = curl_init();
  curl_setopt ($ch, CURLOPT_URL, "$file");
  curl_setopt ($ch, CURLOPT_HEADER, 0);
  curl_exec ($ch);
  curl_close ($ch);

  }

?>