Файл: modules/video/handler/upload.php
Строк: 81
<?php
if (!empty($_FILES['file']))
{
$dir = HOME.'/files/video/'.$user_id;
if (!is_dir($dir)) mkdir(HOME.'/files/video/'.$user_id,0777);
$dir_screen = HOME.'/files/video_screen/'.$user_id;
if (!is_dir($dir_screen)) mkdir(HOME.'/files/video_screen/'.$user_id,0777);
$file_name = time().''.$_FILES['file']['name'].'';
$file_size = $_FILES['file']['size'];
if ($file_size < 1 || $file_size >= 1024 * 50000) $err = true;
if(!preg_match("/.mp4/i", $file_name)) $err = true;
if ($err == false)
{
//$media = new ffmpeg_movie($_FILES['file']['tmp_name']);
$thisVideoFile = new ffmpeg_movie($_FILES['file']['tmp_name']);
$duration = $thisVideoFile->getDuration();
$name = 'video_'.$user['count_video'].'';
$file_name = preg_replace ("/[^a-zA-Z0-9-_.]/","", retranslit($file_name));
if(!preg_match("#^([a-zA-ZА-Яа-я0-9-_.s])+$#ui", $file_name)) die('error');
if ($err == false && copy($_FILES['file']['tmp_name'], HOME.'/files/video/'.$user_id.'/'.$file_name) == true)
{
$img = '/files/video_screen/'.$user_id.'/screen_'.time().'.jpg';
$thumbnail = HOME.''.$img.'';
mysql_query("UPDATE `users` SET count_video=count_video+1 WHERE `id` = '".$user_id."'");
mysql_query("INSERT INTO `video` SET `name` = '".check($name)."', `about` = '".check($name)."', `file` = '".check($file_name)."', `img` = '". $img."', `duration` = '".$duration."', `dir` = '".$user_id."',`user_id` = '".$user_id."', `time` = '".time()."'");
$video_id = mysql_insert_id();
// Делаем скрин экрана на 15 секунде
//exec('ffmpeg -i '.HOME.'/files/video/'.$user_id.'/'.check($file_name).''' -an -ss 15 -r 1 -vframes 1 -s 320x240 -y -f mjpeg '.HOME.'/files/video_screen/'.$user_id.'/screen_'.$video_id.'.jpg');
$frame = 10;
$frame = $thisVideoFile->getFrame($frame);
if ($frame) {
$gd_image = $frame->toGDImage();
if ($gd_image) {
imagepng($gd_image, $thumbnail);
imagedestroy($gd_image);
}
}
//if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `audioplaylist` WHERE `user_id` = '".$user_id."' LIMIT 1"),0) == false) mysql_query("INSERT INTO `audioplaylist` SET `user_id` = '".$user_id."', `tracks` = '|".$track_id."|', `count` = 1");
//else
//{
// $arr_pl = mysql_fetch_array(mysql_query("SELECT * FROM `audioplaylist` WHERE `user_id` = '".$user_id."' LIMIT 1"));
// if (!in_array($track_id, explode("||", substr($arr_pl['tracks'], 1, -1)))) mysql_query("UPDATE `audioplaylist` SET `tracks` = '|".$track_id."|".$arr_pl['tracks']."', count=count+1 WHERE `user_id` = '".$user_id."'");
//}
if ($ajax_query == true) exit;
else go(URL.'/modules/video/edit.php?id='.$video_id.'&r='.rand(0000,9999));
}
}
}
?>
<script type="text/javascript">
$(function(){
$('#form').on('submit', function(e){
e.preventDefault();
var $that = $(this),
formData = new FormData($that.get(0));
$.ajax({
url: $that.attr('action'),
type: $that.attr('method'),
contentType: false,
processData: false,
data: formData,
dataType: 'json',
xhr: function(){
var xhr = $.ajaxSettings.xhr(); // получаем объект XMLHttpRequest
xhr.upload.addEventListener('progress', function(evt){ // добавляем обработчик события progress (onprogress)
$('#notifications').html('<?echo '<p>'.lang('Загрузка...','Завантаження...').'</p>';?><progress id="progressbar" value="0" max="100"></progress>').show();
var progressBar = $('#progressbar');
if(evt.lengthComputable) { // если известно количество байт
// высчитываем процент загруженного
var percentComplete = Math.ceil(evt.loaded / evt.total * 100);
// устанавливаем значение в атрибут value тега <progress>
// и это же значение альтернативным текстом для браузеров, не поддерживающих <progress>
progressBar.val(percentComplete).text(percentComplete + '%');
if(percentComplete == 100)
{
$('#notifications').hide();
Page.Go($that.attr('action')+'&r=<?echo time();?>');
}
}
}, false);
return xhr;
},
success: function(json){
if(json){
$that.after(json);
}
}
});
});
});
</script>