attachment.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title></title>
  6. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  7. <script type="text/javascript" src="../internal.js"></script>
  8. <link rel="stylesheet" type="text/css" href="attachment.css"/>
  9. </head>
  10. <body>
  11. <div class="wrapper">
  12. <div class="controller">
  13. <!--<span id="divStatus"></span>-->
  14. <span id="spanButtonPlaceHolder"></span>
  15. </div>
  16. <div class="fieldset flash" id="fsUploadProgress"></div>
  17. <span id="startUpload" style="display: none;"></span>
  18. </div>
  19. <script type="text/javascript" src="../../third-party/swfupload/swfupload.js"></script>
  20. <script type="text/javascript" src="../../third-party/swfupload/swfupload.queue.js"></script>
  21. <script type="text/javascript" src="../../third-party/swfupload/fileprogress.js"></script>
  22. <script type="text/javascript" src="callbacks.js"></script>
  23. <script type="text/javascript" src="fileTypeMaps.js"></script>
  24. <script type="text/javascript">
  25. var swfupload,
  26. filesList=[];
  27. editor.setOpt({
  28. fileFieldName:"upfile"
  29. });
  30. window.onload = function () {
  31. var settings = {
  32. upload_url:editor.options.fileUrl, //附件上传服务器地址
  33. file_post_name:editor.options.fileFieldName, //向后台提交的表单名
  34. flash_url:"../../third-party/swfupload/swfupload.swf",
  35. flash9_url:"../../third-party/swfupload/swfupload_fp9.swf",
  36. post_params:{"PHPSESSID":"<?php echo session_id(); ?>"}, //解决session丢失问题
  37. file_size_limit:"100 MB", //文件大小限制,此处仅是前端flash选择时候的限制,具体还需要和后端结合判断
  38. file_types:"*.*", //允许的扩展名,多个扩展名之间用分号隔开,支持*通配符
  39. file_types_description:"All Files", //扩展名描述
  40. file_upload_limit:100, //单次可同时上传的文件数目
  41. file_queue_limit:10, //队列中可同时上传的文件数目
  42. custom_settings:{ //自定义设置,用户可在此向服务器传递自定义变量
  43. progressTarget:"fsUploadProgress",
  44. startUploadId:"startUpload"
  45. },
  46. debug:false,
  47. // 按钮设置
  48. button_image_url:"../../themes/default/images/filescan.png",
  49. button_width:"100",
  50. button_height:"25",
  51. button_placeholder_id:"spanButtonPlaceHolder",
  52. button_text:'<span class="theFont">'+lang.browseFiles+'</span>',
  53. button_text_style:".theFont { font-size:14px;}",
  54. button_text_left_padding:10,
  55. button_text_top_padding:4,
  56. // 所有回调函数 in handlers.js
  57. swfupload_preload_handler:preLoad,
  58. swfupload_load_failed_handler:loadFailed,
  59. file_queued_handler:fileQueued,
  60. file_queue_error_handler:fileQueueError,
  61. //选择文件完成回调
  62. file_dialog_complete_handler:function(numFilesSelected, numFilesQueued) {
  63. var me = this; //此处的this是swfupload对象
  64. if (numFilesQueued > 0) {
  65. dialog.buttons[0].setDisabled(true);
  66. var start = $G(this.customSettings.startUploadId);
  67. start.style.display = "";
  68. start.onclick = function(){
  69. me.startUpload();
  70. start.style.display = "none";
  71. }
  72. }
  73. },
  74. upload_start_handler:uploadStart,
  75. upload_progress_handler:uploadProgress,
  76. upload_error_handler:uploadError,
  77. upload_success_handler:function (file, serverData) {
  78. try{
  79. var info = eval("("+serverData+")");
  80. }catch(e){}
  81. var progress = new FileProgress(file, this.customSettings.progressTarget);
  82. if(info.state=="SUCCESS"){
  83. progress.setComplete();
  84. progress.setStatus("<span style='color: #0b0;font-weight: bold'>"+lang.uploadSuccess+"</span>");
  85. filesList.push({url:info.url,type:info.fileType,original:info.original});
  86. progress.toggleCancel(true,this,lang.delSuccessFile);
  87. }else{
  88. progress.setError();
  89. progress.setStatus(info.state);
  90. progress.toggleCancel(true,this,lang.delFailSaveFile);
  91. }
  92. },
  93. //上传完成回调
  94. upload_complete_handler:uploadComplete,
  95. //队列完成回调
  96. queue_complete_handler:function(numFilesUploaded){
  97. dialog.buttons[0].setDisabled(false);
  98. // var status = $G("divStatus");
  99. // var num = status.innerHTML.match(/\d+/g);
  100. // status.innerHTML = ((num && num[0] ?parseInt(num[0]):0) + numFilesUploaded) +lang.statusPrompt;
  101. }
  102. };
  103. swfupload = new SWFUpload( settings );
  104. //点击OK按钮
  105. dialog.onok = function(){
  106. var map = fileTypeMaps,
  107. str="";
  108. for(var i=0,ci;ci=filesList[i++];){
  109. var src = editor.options.UEDITOR_HOME_URL + "dialogs/attachment/fileTypeImages/"+(map[ci.type]||"icon_default.png");
  110. str += "<p style='line-height: 16px;'><img src='"+ src + "' _src='"+src+"' />" +
  111. "<a href='"+editor.options.filePath + ci.url+"'>" + ci.original + "</a></p>";
  112. }
  113. editor.execCommand("insertHTML",str);
  114. swfupload.destroy();
  115. };
  116. dialog.oncancel = function(){
  117. swfupload.destroy();
  118. }
  119. };
  120. </script>
  121. </body>
  122. </html>