$('#sendImgId').uploadify({ swf:URL.fullPath + 'js/uploadify/uploadify.swf', uploader:URL.operation + "?action=sendImg", width:'25', height:'25', cancelImg:"", buttonImage:"", buttonClass:"", buttonText: '', auto:true, // 是否自动开始 multi:false, // 是否支持多文件上传 simUploadLimit: 1, // 一次同步上传的文件数目 sizeLimit: 1024 * 1024 * 30, // 设置单个文件大小限制 queueSizeLimit: 1, // 队列中同时存在的文件个数限制 fileTypeDesc:'支持格式:jpg/gif/jpeg/png/bmp', fileTypeExts: '*.jpg;*.gif;*.jpeg;*.png;*.bmp', // post 附加在文件的后面 formData : {}, onInit : function(swf){ var obj = swf.wrapper.find("object"); obj.attr({"onmouseover":"this.className='OO_btnlist2_over'", "onmouseout":"this.className='OO_btnlist2_out'", title:'图片'}).addClass("OO_btnlist2_out") .css({"position":"absolute", "margin-top":1}); $("#sendImgId-queue").hide(); }, onUploadComplete: function () { /* 防止库调用自己的*/ }, onUploadError: function() { log("文件上传失败"); }, onUploadSuccess: function(file, data, response){ var x = this; setTimeout(function(){ var name = file.name; name = ' ' + x.img + name.substr(name.lastIndexOf("."), name.length) + ' '; insertMsgBlock({type:"wbim_msgr", nick:null, date:x.date.replace(_dateRegExp, ""), msg:name}); scrollToEnd(); // 保存记录 savePanelRecord(_curTalkObj.getJid(), {self:_curTalkObj.getUser(), date:x.date, msg:name}); AjaxUtil.sendOpAct('act_tf_send_msg', JSON.stringify({jid:_curTalkObj.getJid(), date:x.date, val:name})); }, '100'); }, onUploadStart : function(file) { // 创建 图片名称 var x = Math.random() + ""; this.img = "img_" + x.replace(/0\./, ""); this.date = getFormatDate(); // 设置接收对象 $('#sendImgId').uploadify("settings", // 方法名称 "formData", // name {"to":_curTalkObj.getJid(), "date":this.date, "img":this.img, "r":MyInfo.getRdom()}); // value } });
中文文档:http://www.yauld.cn/uploadifydoc/
多文件上传例子:http://lisanlai.iteye.com/blog/680785