upload.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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('upload')?>?cid='+cid;
  50. }
  51. var upmsg = 0;
  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. }
  79. deferred.resolve();
  80. }
  81. });
  82. });
  83. // 返回的是 promise 对象
  84. return deferred.promise();
  85. }
  86. ,'before-send':function(block){
  87. var deferred = WebUploader.Deferred();
  88. if (block.file.ret){//此处跳过秒传的文件
  89. deferred.reject();
  90. }else{
  91. deferred.resolve();
  92. }
  93. return deferred.promise();
  94. }
  95. });
  96. <?php } ?>
  97. var uploader = WebUploader.create({
  98. swf: '<?=Web_Path?>packs/plupload/js/Uploader.swf',
  99. server: '<?=$uploadsave?>',
  100. pick: '#picker',
  101. chunked: true,
  102. chunkSize : 6*1024*1024,
  103. fileVal: 'video',
  104. accept: {
  105. title: '视频文件上传',
  106. extensions: '<?php echo implode(',',array_filter(explode('|', Up_Ext)));?>',
  107. //mimeTypes: 'video/*,audio/*,application/*'
  108. },
  109. fileNumLimit: 1000,
  110. fileSizeLimit: 50000 * 1024 * 1024,
  111. fileSingleSizeLimit: 50000 * 1024 * 1024
  112. });
  113. uploader.on( 'fileQueued', function( file ) {
  114. $('#thelist').append( '<div id="' + file.id + '" class="item">' +
  115. '<h5 class="info">' + file.name + '</h5>' +
  116. '<p class="state" style="color:#f90">等待上传...</p>' +
  117. '</div>' );
  118. $('#thelist').addClass('bord');
  119. });
  120. $('#ctlBtn').click(function(event) {
  121. uploader.upload();
  122. uploader.on( 'uploadProgress', function( file, percentage ) {
  123. var $li = $( '#'+file.id ),
  124. $percent = $li.find('.progress .progress-bar');
  125. if ( !$percent.length ) {
  126. $percent = $('<div class="progress progress-striped active">' +
  127. '<div class="progress-bar" role="progressbar" style="width: 0%;background-color:#666;">' +
  128. '</div>' +
  129. '</div>').appendTo( $li ).find('.progress-bar');
  130. }
  131. $li.find('p.state').html('<font color=blue>上传中...</font>');
  132. $percent.css( 'width', percentage * 100 + '%' );
  133. });
  134. uploader.on( 'uploadSuccess', function( file,json ) {
  135. if(upmsg == 2){
  136. $( '#'+file.id ).find('p.state').html('<font color=red>秒传失败:相同标题视频存在</font>');
  137. } else if(upmsg == 1){
  138. $( '#'+file.id ).find('p.state').html('<font color=#080>秒传成功,已加入转码队列</font>');
  139. $.get('<?=Web_Path?>ting.php');
  140. } else if(json.msg == 'ok'){
  141. $( '#'+file.id ).find('p.state').html('<font color=#080>上传成功,已加入转码队列</font>');
  142. $.get('<?=Web_Path?>ting.php');
  143. }else{
  144. $( '#'+file.id ).find('p.state').html('<font color=red>上传失败:'+json.msg+'</font>');
  145. }
  146. });
  147. uploader.on( 'uploadError', function( file ) {
  148. $( '#'+file.id ).find('p.state').html('<font color=red>上传出错</font>');
  149. });
  150. uploader.on( 'uploadComplete', function( file ) {
  151. $( '#'+file.id ).find('.progress').fadeOut();
  152. });
  153. });
  154. </script>
  155. </body>
  156. </html>