ajaxuploadlargefile.html.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. $webRoot = $this->app->getWebRoot();
  3. $jsRoot = $webRoot . "js/";
  4. js::import($jsRoot . 'uploader/min.js');
  5. css::import($jsRoot . 'uploader/min.css');
  6. js::set('uid', $uid);
  7. js::set('module', $module);
  8. ?>
  9. <div id='uploader' class="uploader" data-ride="uploader" data-url="<?php echo $this->createLink('file', 'ajaxUploadLargeFile', "module=$module&uid=$uid")?>">
  10. <div class="uploader-message text-center">
  11. <div class="content"></div>
  12. <button type="button" class="close">×</button>
  13. </div>
  14. <div class="uploader-files file-list file-list-lg" data-drag-placeholder="<?php echo $lang->file->drag?>"></div>
  15. <div class="uploader-actions">
  16. <div class="uploader-status pull-right text-muted"></div>
  17. <button type="button" class="btn btn-link uploader-btn-browse"><i class="icon icon-plus"></i> <?php echo $lang->file->addFile?></button>
  18. <button type='button' class='btn btn-link uploader-btn-start'><i class='icon icon-arrow-up'></i><?php echo $lang->file->beginUpload;?></button>
  19. </div>
  20. </div>
  21. <script>
  22. var durationList = {};
  23. $('#uploader').uploader({
  24. limitFilesCount: 1,
  25. filters:
  26. {
  27. mime_types: [
  28. {title: 'uploadImages', extensions: 'jpeg,jpg,gif,png,.bmp,flv,swf,mkv,avi,rm,rmvb,mpeg,mpg,ogg,ogv,mov,wmv,mp4,webm,mp3,wav,mid,doc,docx,dot,wps,wri,pdf,ppt,pptx,xls,xlsx,ett,xlt,xlsm,csv'},
  29. ],
  30. prevent_duplicates: true
  31. },
  32. onUploadProgress: function(file)
  33. {
  34. $('#uploader .file .file-icon .icon').addClass('icon-file');
  35. },
  36. onUploadComplete: function(file)
  37. {
  38. $('#uploader .file .file-icon .icon').addClass('icon-file');
  39. },
  40. onFilesAdded: function(files)
  41. {
  42. var self = this;
  43. for(var i = 0; i < files.length; i++)
  44. {
  45. var file = files[i]
  46. if(file.ext == 'mp4' || file.ext == 'wmv' || file.ext == 'mp3')
  47. {
  48. var fileurl = URL.createObjectURL(file.getNative());
  49. var audioElement = new Audio(fileurl);
  50. audioElement.addEventListener('loadedmetadata', function (_event) {
  51. durationList[file.id] = parseInt(audioElement.duration);
  52. })
  53. }
  54. }
  55. },
  56. onBeforeUpload: function(file)
  57. {
  58. var duration = null;
  59. if(durationList[file.id]) duration = durationList[file.id];
  60. this.plupload.setOption(
  61. {
  62. 'multipart_params':
  63. {
  64. label: file.ext ? file.name.substr(0, file.name.length - file.ext.length - 1) : file.name,
  65. uuid: file.id,
  66. size: file.size,
  67. duration: duration,
  68. }
  69. });
  70. }
  71. })
  72. </script>