1. 程式人生 > >flash上傳頭像外掛使用說明

flash上傳頭像外掛使用說明

元件下載地址

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();
}