Advertisement
blackseabreathe

Untitled

Jul 6th, 2022
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Форма
  2. <form enctype="multipart/form-data" method="post" id="uploadVideo">
  3. <input type="hidden" name="<? echo ini_get("session.upload_progress.name"); ?>" value="bar">
  4. <div class="file-upload">
  5. <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">
  6. <span>+ Видео</span></label>
  7. <div class="filename df alice fw"></div>
  8. </div>
  9. <button type="button" name="send" class="uploadVideoBtn">Загрузить</button>
  10. </form>
  11.  
  12. // 1-ый Ajax
  13.  
  14. $('.uploadVideoBtn').on('click', function(){ // клик на кнопку "загрузить"
  15.  
  16. var formData = $('#uploadVideo').serializefiles();
  17. formData.append('func','upload');
  18.  
  19. $.ajax({
  20. url: 'upload.php',  // адрес написан от балды чтобы не палить реальный
  21. type: 'post',
  22. dataType: 'json',
  23. data: formData,
  24. async: true,
  25. cache: false,
  26. contentType: false,
  27. processData: false,
  28. success: function(json){
  29. if(typeof json.success !== 'undefined'){
  30. $.jGrowl(json.success);
  31. } else if(typeof json.error !== 'undefined'){
  32. $.jGrowl(json.error);
  33. }
  34. },
  35. error: function(json, jqXHR, status, errorThrown, exception){
  36. alert(JSON.stringify(json));
  37. return $.jGrowl('ОШИБКА AJAX запроса: ' + status, jqXHR, json);
  38. }
  39. });
  40.  
  41. getting_progress();  // вот тут сразу же отправляем 2-ой Ajax
  42.  
  43. });
  44.  
  45.  
  46. function getting_progress(){ // 2-ой Ajax
  47. var interval_id = setInterval(function () {
  48. $.ajax({
  49. url: "progress.php", // адрес написан от балды чтобы не палить реальный
  50. type: "POST",
  51. dataType: 'json',
  52. //async: true,
  53. success: function(json){
  54. if(typeof json.success !== 'undefined'){
  55. $.jGrowl(json.success);
  56. clearInterval(interval_id);
  57. } else if(typeof json.error !== 'undefined'){
  58. $.jGrowl(json.error);
  59. }
  60. },
  61. error: function(json, jqXHR, status, errorThrown, exception){
  62. alert(JSON.stringify(json));
  63. return $.jGrowl('ОШИБКА AJAX запроса: ' + status, jqXHR, json);
  64. }
  65. });
  66. }, 1000);
  67. }
  68.  
  69.  
  70. progress.php
  71.  
  72. <?
  73.  
  74. session_start();
  75.  
  76.  
  77. $key = ini_get("session.upload_progress.prefix").'bar';
  78.  
  79. if(isset($_SESSION[$key])){
  80. echo json_encode(['error' => 'yes '], JSON_UNESCAPED_UNICODE);
  81. exit();
  82. }
  83.  
  84. else{
  85.  
  86.  
  87. echo json_encode(['error' => 'no '], JSON_UNESCAPED_UNICODE);
  88. exit();
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement