upapi.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>视频上传</title>
  8. <link rel="stylesheet" type="text/css" href="<?=Web_Path?>packs/plupload/css/webuploader.css">
  9. <script type="text/javascript" src="<?=Web_Path?>packs/jquery/jquery.min.js"></script>
  10. <style>
  11. #upload_box{width:96%;margin:2% auto;border: 1px dashed #999;box-sizing: border-box;}
  12. h5,p{margin: 10px 5px;}
  13. .btns{padding: 10px 20px;position: relative;}
  14. .bord{border : 1px solid #3bb4f2;border-radius: 5px;}
  15. #picker{width:100px;height:48px;}
  16. #ctlBtn{position: absolute;top:10px;right:20px;width: 86px;height:42px;cursor: pointer;line-height: 42px;font-size: 14px;border-radius: 3px;background-color: #e6e6e6;color: #444;text-align: center;background-color: #e6e6e6;}
  17. #thelist{margin: 10px 20px;padding: 5px;}
  18. .item{border-bottom: 1px dashed #999;}
  19. .progress-bar{height:10px;margin-bottom:6px;}
  20. </style>
  21. </head>
  22. <body>
  23. <p style="width:96%;margin:2% auto;">
  24. 选择上传分类:
  25. <select name="cid" id="cid" onchange="get_class()">
  26. <option value="0">默认分类</option>
  27. <?php
  28. foreach ($vlist as $row) {
  29. $sel = $cid == $row->id ? ' selected' : '';
  30. echo '<option value="'.$row->id.'"'.$sel.'>'.$row->name.'</option>';
  31. }
  32. ?>
  33. </select>
  34. </p>
  35. <div id="upload_box">
  36. <div id="uploader" class="wu-example">
  37. <!--用来存放文件信息-->
  38. <div class="btns">
  39. <div id="picker">选择文件</div>
  40. <div id="ctlBtn">开始上传</div>
  41. </div>
  42. <div id="thelist"></div>
  43. </div>
  44. </div>
  45. <script type="text/javascript" src="<?=Web_Path?>packs/plupload/js/webuploader.js"></script>
  46. <script type="text/javascript">
  47. function get_class(){
  48. var cid = $('#cid').val();
  49. location.href='<?=site_url('upapi')?>?cid='+cid;
  50. }
  51. var upmsg = 0,upname = null,uppic = null,upm3u8 = null,uppurl = null,upsize = null,upsec = null;
  52. <?php if(Up_Miao == 1){ ?>
  53. WebUploader.Uploader.register({
  54. 'before-send-file': function(file){
  55. var uploader = this.owner;
  56. var deferred = WebUploader.Deferred();
  57. uploader.md5File(file.source)
  58. .progress(function(percentage) {
  59. //console.log('Percentage:', percentage);
  60. $('#'+file.id).find('p.state').html('<font color=#0000ff>秒传计算中...'+parseInt(percentage*100)+'%</font>');
  61. })
  62. .then(function(ret) {
  63. file.md5 = ret;
  64. //取得MD5值后,请求服务器查询对应文件是否已存在(秒传)
  65. $.ajax({
  66. type: 'POST',
  67. url: '<?=$uploadsave?>',
  68. data: {'md5':file.md5,'filename':file.name,'filesize':file.size},
  69. dataType: 'json',
  70. async:true,//是否使用异步
  71. success: function(result){
  72. if(result.msg == 'yes'){
  73. upmsg = 2;
  74. file.ret = 1;
  75. } else if(result.msg == 'ok'){
  76. upmsg = 1;
  77. file.ret = 1;
  78. upname = result.name;
  79. uppic = result.pic;
  80. upm3u8 = result.m3u8;
  81. uppurl = result.purl;
  82. upsize = result.size;
  83. upsec = result.sec;
  84. }
  85. deferred.resolve();
  86. }
  87. });
  88. });
  89. // 返回的是 promise 对象
  90. return deferred.promise();
  91. }
  92. ,'before-send':function(block){
  93. var deferred = WebUploader.Deferred();
  94. if (block.file.ret){//此处跳过秒传的文件
  95. deferred.reject();
  96. }else{
  97. deferred.resolve();
  98. }
  99. return deferred.promise();
  100. }
  101. });
  102. <?php } ?>
  103. var uploader = WebUploader.create({
  104. swf: '<?=Web_Path?>packs/plupload/js/Uploader.swf',
  105. server: '<?=$uploadsave?>',
  106. pick: '#picker',
  107. chunked: true,
  108. chunkSize : 6*1024*1024,
  109. fileVal: 'video',
  110. accept: {
  111. title: '视频文件上传',
  112. extensions: '<?php echo implode(',',array_filter(explode('|', Up_Ext)));?>',
  113. //mimeTypes: 'video/*,audio/*,application/*'
  114. },
  115. fileNumLimit: 1000,
  116. fileSizeLimit: 50000 * 1024 * 1024,
  117. fileSingleSizeLimit: 50000 * 1024 * 1024
  118. });
  119. uploader.on( 'fileQueued', function( file ) {
  120. $('#thelist').append( '<div id="' + file.id + '" class="item">' +
  121. '<h5 class="info">' + file.name + '</h5>' +
  122. '<p class="state" style="color:#f90">等待上传...</p>' +
  123. '</div>' );
  124. $('#thelist').addClass('bord');
  125. });
  126. $('#ctlBtn').click(function(event) {
  127. uploader.upload();
  128. uploader.on( 'uploadProgress', function( file, percentage ) {
  129. var $li = $( '#'+file.id ),
  130. $percent = $li.find('.progress .progress-bar');
  131. if ( !$percent.length ) {
  132. $percent = $('<div class="progress progress-striped active">' +
  133. '<div class="progress-bar" role="progressbar" style="width: 0%;background-color:#666;">' +
  134. '</div>' +
  135. '</div>').appendTo( $li ).find('.progress-bar');
  136. }
  137. $li.find('p.state').html('<font color=blue>上传中...</font>');
  138. $percent.css( 'width', percentage * 100 + '%' );
  139. });
  140. uploader.on( 'uploadSuccess', function( file,json) {
  141. if(upmsg == 2){
  142. $( '#'+file.id ).find('p.state').html('<font color=red>秒传失败:相同标题视频存在</font>');
  143. } else if(upmsg == 1){
  144. $( '#'+file.id ).find('p.state').html('<font color=#080>秒传成功,已加入转码队列</font>');
  145. $.get('<?=Web_Path?>ting.php');
  146. } else if(json.msg == 'ok'){
  147. upname = json.name;
  148. uppic = json.pic;
  149. upm3u8 = json.m3u8;
  150. uppurl = json.purl;
  151. upsize = json.size;
  152. upsec = json.sec;
  153. var html = '<br>视频名称:'+upname+'<br>视频图片:'+uppic+'<br>播放地址:'+uppurl+'<br>M3U8地址:'+upm3u8+'<br>视频大小:'+upsize+'<br>视频时长:'+upsec;
  154. $( '#'+file.id ).find('p.state').html('<font color=#080>上传成功,已加入转码队列'+html+'</font>');
  155. $.get('<?=Web_Path?>ting.php');
  156. }else{
  157. $( '#'+file.id ).find('p.state').html('<font color=red>上传失败:'+json.msg+'</font>');
  158. }
  159. });
  160. uploader.on( 'uploadError', function( file ) {
  161. $( '#'+file.id ).find('p.state').html('<font color=red>上传出错</font>');
  162. });
  163. uploader.on( 'uploadComplete', function( file ) {
  164. $( '#'+file.id ).find('.progress').fadeOut();
  165. });
  166. });
  167. </script>
  168. </body>
  169. </html>