您的位置:首页 > 其它

flash上传头像插件使用说明

2015-02-11 13:46 351 查看
组件下载地址

flash上传头像剪裁预览组件_头像上传插件 - 免费开源
http://www.hdfu.net/
参数说明:

imgUrl:默认图片地址

uploadUrl:接收图片url

uploadSrc = true,是否上传源图

showCame = true,是否显示摄像头

pCut:=162|162,裁剪框大小(自定义)

pSize=162|162,预览保存图片大小

pData=162|162保存图片大小

保存1张图片时:pSize = 162|162&pData=162|162

保存2张图片时:pSize = 162|162|48|48&pData=162|162|48|48

例子:

前端:

<!DOCTYPE html>

<html lang="zh-CN">

<%@ page pageEncoding="utf-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%

String _path = request.getContextPath();

%>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>flash上传头像组件演示</title>

<script type="text/javascript">

//上传成功,js回调函数

function uploadevent(status,picUrl,callbackdata){

alert(picUrl); //后端存储图片

// alert(callbackdata);

status += '';

switch(status){

case '1':break;

case '-1':window.location.reload(); break;

default:window.location.reload();

}

}

</script>

</head>

<body>

<div>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"

width="650" height="450" id="myMovieName">

<param name="movie" value="<%=_path%>/avatar.swf">

<param name="quality" value="high">

<param name="bgcolor" value="#FFFFFF">

<param name="flashvars" value="imgUrl=<%=_path%>/img/user_logo.jpg&uploadUrl=<%=_path%>/logo/upload&uploadSrc=false&pCut=162|162&pSize=162|162&pData=162|162&showBe=false" />

<embed src="<%=_path%>/avatar.swf" quality="high" bgcolor="#FFFFFF" width="650" height="450" wmode="transparent"

flashvars="imgUrl=<%=_path%>/img/user_logo.jpg&uploadUrl=<%=_path%>/logo/upload&uploadSrc=false"

name="myMovieName" align="" type="application/x-shockwave-flash" allowScriptAccess="always"

pluginspage="http://www.macromedia.com/go/getflashplayer">

</embed>

</object>

</div>

</body>

</html>

后台(java):

@RequestMapping(value="/logo/upload", method=RequestMethod.POST)

public @ResponseBody void uploadCompanyLogo(PrintWriter printWriter, HttpServletRequest request, HttpServletResponse response){

String userId = request.getSession().getAttribute("userId").toString();

String filename = "logo.jpg";

String logoPath = "D:/userLogo/" + userId;

String pic = request.getParameter("pic1"); //保存原图时,此时接收参数应是pic;尺寸1则是pic1,尺寸2则是pic2 。。。

File file = null;

File directory = null;

try {

directory = new File(logoPath);

if (!directory.exists()){

directory.mkdirs();

}

if(!pic.equals("")&&pic!=null){

file = new File(logoPath+"/"+filename);

FileOutputStream fout = null;

fout = new FileOutputStream(file);

fout.write(new BASE64Decoder().decodeBuffer(pic));

fout.close();

}

}

catch (IOException e) {

if (file.exists()){

file.delete();

}

}

printWriter.write("{\"status\":1,\"picUrl\":\""+filename+"\"}");

printWriter.flush();

printWriter.close();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: