1:引入需要的文件
<script src="<%=basePath%>style/js/jquery.uploadify.min.js"></script>
<link href="<%=basePath%>style/css/uploadify.css" rel="stylesheet">
2:初始化上传组件
function initUploadify() {
$("#btnUploadify").uploadify({
height: 30,
swf: "<%=basePath%>style/img/uploadify.swf",
cancelImage: "<%=basePath%>style/img/uploadify-cancel.png",
uploader: ‘<%=basePath%>common/op/uploadFileForMedia.shtml?type=image‘,
fileTypeDesc: ‘文档类型‘,
fileTypeExts: ‘*.jpg;*.png;*.gif;*.jpeg;*.bmp‘,
width: 100,
multi: false,
fileSizeLimit : ‘2MB‘, //设置单个文件大小限制
method: ‘post‘,
fileObjName: ‘uploadify‘,
buttonText: "选择文件",
onUploadSuccess: function (file, data, response) {
//上传成功
if (response) {
var dataJson = eval("(" + data + ")");
if(!dataJson.basepath || !dataJson.filename){
$(‘#errmsg‘).calert(‘alert‘,‘封面上传失败!‘);
}else{
$(".cur-edit").parents(".uploadImgWrap").find(".uploadImg").attr("src","<%=basePath%>"+ dataJson.basepath + "\/" + dataJson.filename);
$(".cur-edit").parents(".uploadImgWrap").find(".mediaIdInput").val(dataJson.mediaId);
}
}
},
onUploadError : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue) {
},
auto: true
});
}
3:解决方案
<input type="hidden" id="sessionId" value="${pageContext.session.id}" />
uploader: ‘<%=basePath%>common/op/uploadFileForMedia.shtml;jsessionid=‘ + $("#sessionId").val()+‘?type=image‘,
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-09-30 06:58:23