<?php
header("Cache-Control: no-cache, must-revalidate"); // говорим браузеру что-бы он не кешировал эту страницу
header("Pragma: no-cache");
set_time_limit(1600);
while(ob_get_level())
    ob_end_clean();
include_once (coreAudio . 'class.Main.php');
if(empty($_SESSION['audioSession']))
    Main::fileLocation('no', true);
if(array_key_exists('prevSong', $_SESSION) === false) {
    $_SESSION['prevSong'] = '';
}
$file = 'no';
$error = false;
if(!empty($get['_file']) && !empty($get['_dataID']))
{
    $file   = $get['_file'];
    $dataID = $get['_dataID'];
    if(is_readable(coreAudio . 'response/' . $file . '.data.r') === true)
    {
        $data = include_once coreAudio . 'response/' . $file . '.data.r';

        if(array_key_exists($dataID, $data['item']) === true)
        {
            $referer = $data['referer'];
            $data = $data['item'][$dataID];
            include_once (coreAudio . 'class.audioUrlDecode.php');
            $a = new audioUrlDecode();

            $data['url'] = $a->getUrlFile($data['url']);

            $data['file'] = $_SESSION['audioSession'] . '-' . $data['file'];
            $file = 'file/' . $data['file'];

            $error = false;
            if($_SESSION['prevSong'] != $file && is_readable(filesPathAudio . $_SESSION['prevSong']) === true) {
                unlink(filesPathAudio . $_SESSION['prevSong']);
            }

            $_SESSION['prevSong'] = $file;
            if(Main::uploadFile(filesPathAudio . $file, $data['url'], $referer) === false) {
                $error = true;
            }

            if($error === false && $user['set_online_hide'] == 0)
                DB::$pdo->query("INSERT INTO `listen_music` SET `id_user` = '" . $user['id'] . "', `time` = '" . (time() + $data['dur']) . "', `artist` = '" . $data['artist'] . "', `title` = '" . $data['title'] . "' ON DUPLICATE KEY UPDATE `time` = '" . (time() + $data['dur']) . "', `artist` = '" . $data['artist'] . "', `title` = '" . $data['title'] . "'");
        }
    }
}
Main::fileLocation($file, $error);
?>