Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Форма
- <form enctype="multipart/form-data" method="post" id="uploadVideo">
- <input type="hidden" name="<? echo ini_get("session.upload_progress.name"); ?>" value="bar">
- <div class="file-upload">
- <label class="cu"><input type="file" name="video[]" accept="video/avi, video/mp4, video/flv, video/mov, video/mkv, video/ogg, video/wmv, video/webm, video/ogv">
- <span>+ Видео</span></label>
- <div class="filename df alice fw"></div>
- </div>
- <button type="button" name="send" class="uploadVideoBtn">Загрузить</button>
- </form>
- // 1-ый Ajax
- $('.uploadVideoBtn').on('click', function(){ // клик на кнопку "загрузить"
- var formData = $('#uploadVideo').serializefiles();
- formData.append('func','upload');
- $.ajax({
- url: 'upload.php', // адрес написан от балды чтобы не палить реальный
- type: 'post',
- dataType: 'json',
- data: formData,
- async: true,
- cache: false,
- contentType: false,
- processData: false,
- success: function(json){
- if(typeof json.success !== 'undefined'){
- $.jGrowl(json.success);
- } else if(typeof json.error !== 'undefined'){
- $.jGrowl(json.error);
- }
- },
- error: function(json, jqXHR, status, errorThrown, exception){
- alert(JSON.stringify(json));
- return $.jGrowl('ОШИБКА AJAX запроса: ' + status, jqXHR, json);
- }
- });
- getting_progress(); // вот тут сразу же отправляем 2-ой Ajax
- });
- function getting_progress(){ // 2-ой Ajax
- var interval_id = setInterval(function () {
- $.ajax({
- url: "progress.php", // адрес написан от балды чтобы не палить реальный
- type: "POST",
- dataType: 'json',
- //async: true,
- success: function(json){
- if(typeof json.success !== 'undefined'){
- $.jGrowl(json.success);
- clearInterval(interval_id);
- } else if(typeof json.error !== 'undefined'){
- $.jGrowl(json.error);
- }
- },
- error: function(json, jqXHR, status, errorThrown, exception){
- alert(JSON.stringify(json));
- return $.jGrowl('ОШИБКА AJAX запроса: ' + status, jqXHR, json);
- }
- });
- }, 1000);
- }
- progress.php
- <?
- session_start();
- $key = ini_get("session.upload_progress.prefix").'bar';
- if(isset($_SESSION[$key])){
- echo json_encode(['error' => 'yes '], JSON_UNESCAPED_UNICODE);
- exit();
- }
- else{
- echo json_encode(['error' => 'no '], JSON_UNESCAPED_UNICODE);
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement