Файл: voice/index.php
Строк: 81
<?php
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/user.php';
$arrAnswer = [ 'Успешно', 'Ошибка файла', 'Ошибка контакта', 'No access' ];
$__rollBack = function ( $text, $id ) {
if ( $id <> 0 ) :
mysql_query ( "DELETE FROM `mail` WHERE `id` = $id" );
endif;
throw new Exception ( $text );
return $text;
};
if ( isset ( $user['id'] ) AND !empty ( $_POST['data'] ) ) :
$ini = explode ( ",", $_POST['data'] );
$fil = $user['id'].'-'. date ( 'Y-m-d-H-i-s' ) .'.ogg';
$url = 'https://' . $_SERVER['SERVER_NAME'] .'/user/voice/';
$data = [
'time' => $time,
'select' => $ini[1]==='audio'?'audio':'video',
'audio' => $url.'ogg/audio/'.$fil,
'video' => $url.'ogg/video/'.$fil,
'id_user' => $user['id'],
'id_kont' => $ini[0],
];
$args = [
'time' => FILTER_DEFAULT,
'select' => FILTER_DEFAULT,
'audio' => FILTER_VALIDATE_URL,
'video' => FILTER_VALIDATE_URL,
'id_user' => [ 'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FLAG_ALLOW_OCTAL,
'options' => [ 'default' => 0, 'min_range' => 1 ]
],
'id_kont' => [ 'filter' => FILTER_VALIDATE_INT,
'flags' => FILTER_FLAG_ALLOW_OCTAL,
'options' => [ 'default' => 0, 'min_range' => 1 ]
] ];
query ( vsprintf ("
INSERT INTO mail ( id_user, id_kont, time, msg )
SELECT co.id_user, co.id_kont, '%u',
CASE WHEN 'audio' <=> '%s'
THEN '[mp3]%s[/mp3]'
ELSE '[mp4]%s[/mp4]'
END FROM users_konts AS co
JOIN user AS us ON us.id <=> co.id_kont
WHERE co.id_user IN ( co.id_user, co.id_kont )
HAVING co.id_user = '%u' AND co.id_kont = '%u'",
filter_var_array ( $data, $args ) ) );
try {
if ( $id = mysql_insert_id ( ) ) :
$tmp = preg_match ( "%^[[:alnum:]-/]+$%i", $_FILES['voice']['tmp_name'] )
<> 0 ? $_FILES['voice']['tmp_name'] : 0;
header ( "Content-type: audio/ogg" );
header ( "Content-transfer-encoding:binary" );
header ( "Accept-Ranges:bytes" );
if ( is_uploaded_file ( $tmp ) <> 0
and @move_uploaded_file ( $tmp, __DIR__.'/ogg/'.$data['select'].'/'.$fil ) <> 0 ) :
$__rollBack ( $arrAnswer[0], 0 );
endif;
$__rollBack ( $arrAnswer[1], $id );
endif;
$__rollBack ( $arrAnswer[2], 0 );
} catch ( Exception $e ) {
die ( json_encode ( $e -> getMessage ( ), JSON_UNESCAPED_UNICODE ) );
}
else:
die ( $arrAnswer[3] );
endif;