Hplus(H+) 后台主题 UI 框架
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Debug="true" Inherits="Upload" %>
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
/*
|
||||
温馨提示:
|
||||
在flash的参数名upload_url中可自行定义一些参数(请求方式:POST),定义后在服务器端获取即可,比如可以应用到用户验证,文件的保存名等。
|
||||
本示例未作极致的用户体验与严谨的安全设计(如用户直接访问此页时该如何,万一客户端数据不可信时验证文件的大小、类型等),只保证正常情况下无误,请阁下注意。
|
||||
*/
|
||||
public partial class Upload : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
Result result = new Result();
|
||||
result.avatarUrls = new ArrayList();
|
||||
result.success = false;
|
||||
result.msg = "Failure!";
|
||||
//取服务器时间+8位随机码作为部分文件名,确保文件名无重复。
|
||||
string fileName = DateTime.Now.ToString("yyyyMMddhhmmssff") + CreateRandomCode(8);
|
||||
//定义一个变量用以储存当前头像的序号
|
||||
int avatarNumber = 1;
|
||||
//遍历所有文件域
|
||||
foreach(string fieldName in Request.Files.AllKeys)
|
||||
{
|
||||
HttpPostedFile file = Request.Files[fieldName];
|
||||
//处理原始图片(默认的 file 域的名称是__source,可在插件配置参数中自定义。参数名:src_field_name)
|
||||
//如果在插件中定义可以上传原始图片的话,可在此处理,否则可以忽略。
|
||||
if(fieldName == "__source")
|
||||
{
|
||||
//文件名,如果是本地或网络图片为原始文件名(不含扩展名)、如果是摄像头拍照则为 *FromWebcam
|
||||
//fileName = file.FileName;
|
||||
//当前头像基于原图的初始化参数(即只有上传原图时才会发送该数据),用于修改头像时保证界面的视图跟保存头像时一致,提升用户体验度。
|
||||
//修改头像时设置默认加载的原图url为当前原图url+该参数即可,可直接附加到原图url中储存,不影响图片呈现。
|
||||
string initParams = Request.Form["__initParams"];
|
||||
result.sourceUrl = string.Format("upload/csharp_source_{0}.jpg", fileName);
|
||||
file.SaveAs(Server.MapPath(result.sourceUrl));
|
||||
result.sourceUrl += initParams;
|
||||
/*
|
||||
可在此将 result.sourceUrl 储存到数据库,如果有需要的话。
|
||||
*/
|
||||
}
|
||||
//处理头像图片(默认的 file 域的名称:__avatar1,2,3...,可在插件配置参数中自定义,参数名:avatar_field_names)
|
||||
else if (fieldName.StartsWith("__avatar"))
|
||||
{
|
||||
string virtualPath = string.Format("upload/csharp_avatar{0}_{1}.jpg", avatarNumber, fileName);
|
||||
result.avatarUrls.Add(virtualPath);
|
||||
file.SaveAs(Server.MapPath(virtualPath));
|
||||
/*
|
||||
可在此将 virtualPath 储存到数据库,如果有需要的话。
|
||||
*/
|
||||
avatarNumber++;
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
如下代码在上传接口Upload.aspx中定义了一个user=xxx的参数:
|
||||
var swf = new fullAvatarEditor('swf', {
|
||||
id: 'swf',
|
||||
upload_url: 'Upload.aspx?user=xxx'
|
||||
});
|
||||
在此即可用Request.Form["user"]获取xxx。
|
||||
}
|
||||
*/
|
||||
}
|
||||
result.success = true;
|
||||
result.msg = "Success!";
|
||||
//返回图片的保存结果(返回内容为json字符串,可自行构造,该处使用Newtonsoft.Json构造)
|
||||
Response.Write(JsonConvert.SerializeObject(result));
|
||||
}
|
||||
/// <summary>
|
||||
/// 生成指定长度的随机码。
|
||||
/// </summary>
|
||||
private string CreateRandomCode(int length)
|
||||
{
|
||||
string [] codes = new string [36] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
|
||||
StringBuilder randomCode = new StringBuilder();
|
||||
Random rand = new Random();
|
||||
for ( int i =0; i < length; i++ )
|
||||
{
|
||||
randomCode.Append(codes [rand.Next(codes.Length)]);
|
||||
}
|
||||
return randomCode.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 表示图片的上传结果。
|
||||
/// </summary>
|
||||
private struct Result
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示图片是否已上传成功。
|
||||
/// </summary>
|
||||
public bool success;
|
||||
/// <summary>
|
||||
/// 自定义的附加消息。
|
||||
/// </summary>
|
||||
public string msg;
|
||||
/// <summary>
|
||||
/// 表示原始图片的保存地址。
|
||||
/// </summary>
|
||||
public string sourceUrl;
|
||||
/// <summary>
|
||||
/// 表示所有头像图片的保存地址,该变量为一个数组。
|
||||
/// </summary>
|
||||
public ArrayList avatarUrls;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Upload.aspx.vb" Debug="true" Inherits="Upload" %>
|
||||
@@ -0,0 +1,80 @@
|
||||
REM 温馨提示:
|
||||
REM 在flash的参数名upload_url中可自行定义一些参数(请求方式:POST),定义后在服务器端获取即可,比如可以应用到用户验证,文件的保存名等。
|
||||
REM 本示例未作极致的用户体验与严谨的安全设计(如用户直接访问此页时该如何,万一客户端数据不可信时验证文件的大小、类型等),只保证正常情况下无误,请阁下注意。
|
||||
Imports Newtonsoft.Json
|
||||
Partial Class Upload
|
||||
Inherits System.Web.UI.Page
|
||||
|
||||
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
|
||||
Dim UploadResult As Result = New Result()
|
||||
UploadResult.avatarUrls = New ArrayList()
|
||||
UploadResult.msg = "Failure!"
|
||||
UploadResult.sourceUrl = String.Empty
|
||||
UploadResult.success = False
|
||||
REM 取服务器时间+8位随机码作为部分文件名,确保文件名无重复。
|
||||
Dim FileName As String = Now.ToString("yyyyMMddhhmmssff") & CreateRandomCode(8)
|
||||
REM 定义一个变量用以储存当前头像的序号
|
||||
Dim AvatarNumber As Integer = 1
|
||||
Dim FieldName As String
|
||||
For Each FieldName In Request.Files.AllKeys
|
||||
Dim File As HttpPostedFile = Request.Files(FieldName)
|
||||
REM 处理原始图片(默认的 file 域的名称是__source,可在插件配置参数中自定义。参数名:src_field_name)
|
||||
REM 如果在插件中定义可以上传原始图片的话,可在此处理,否则可以忽略。
|
||||
If FieldName = "__source" Then
|
||||
REM 文件名,如果是本地或网络图片为原始文件名(不含扩展名)、如果是摄像头拍照则为 *FromWebcam
|
||||
REM FileName = file.FileName;
|
||||
REM 当前头像基于原图的初始化参数(即只有上传原图时才会发送该数据),用于修改头像时保证界面的视图跟保存头像时一致,提升用户体验度。
|
||||
REM 修改头像时设置默认加载的原图url为当前原图url+该参数即可,可直接附加到原图url中储存,不影响图片呈现。
|
||||
Dim InitParams As String = Request.Form("__initParams")
|
||||
UploadResult.sourceUrl = String.Format("upload/vb_source_{0}.jpg", FieldName)
|
||||
File.SaveAs(Server.MapPath(UploadResult.sourceUrl))
|
||||
UploadResult.sourceUrl = UploadResult.sourceUrl & InitParams
|
||||
REM 可在此将 UploadResult.sourceUrl 储存到数据库,如果有需要的话
|
||||
REM 处理头像图片(默认的 file 域的名称:__avatar1,2,3...,可在插件配置参数中自定义,参数名:avatar_field_names)
|
||||
Else If fieldName.StartsWith("__avatar") Then
|
||||
Dim VirtualPath As String = String.Format("upload/vb_avatar{0}_{1}.jpg", AvatarNumber, FileName)
|
||||
UploadResult.avatarUrls.Add(VirtualPath)
|
||||
File.SaveAs(Server.MapPath(VirtualPath))
|
||||
AvatarNumber = AvatarNumber + 1
|
||||
End If
|
||||
REM Else
|
||||
REM 如下代码在上传接口Upload.aspx中定义了一个user=xxx的参数:
|
||||
REM var swf = new fullAvatarEditor('swf', {
|
||||
REM id: 'swf',
|
||||
REM upload_url: 'Upload.aspx?user=xxx'
|
||||
REM });
|
||||
REM 在此即可用Request.Form("user")获取xxx。
|
||||
REM End If
|
||||
Next
|
||||
UploadResult.success = True
|
||||
UploadResult.msg = "Success!"
|
||||
'返回图片的保存结果(返回内容为json字符串,可自行构造,该处使用Newtonsoft.Json构造)
|
||||
Response.Write(JsonConvert.SerializeObject(UploadResult))
|
||||
End Sub
|
||||
|
||||
'生成指定长度的随机码。
|
||||
Private Function CreateRandomCode(ByVal Length As Integer) As String
|
||||
Randomize()
|
||||
Dim RandCode As String = RandCode = String.Empty
|
||||
Dim RandChar As String = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
|
||||
Dim RandCharArray As Array = Split(RandChar, ",")
|
||||
Dim i As Integer
|
||||
For i = 1 To Length
|
||||
RandCode = RandCode & RandCharArray(Int(36 * Rnd()))
|
||||
Next
|
||||
CreateRandomCode = RandCode
|
||||
End Function
|
||||
|
||||
REM 表示上传结果
|
||||
Private Structure Result
|
||||
REM 表示图片是否已上传成功。
|
||||
Public success As String
|
||||
REM 自定义的附加消息。
|
||||
Public msg As String
|
||||
REM 表示原始图片的保存地址。
|
||||
Public sourceUrl As String
|
||||
REM 表示所有头像图片的保存地址,该变量为一个数组。
|
||||
Public avatarUrls As ArrayList
|
||||
End Structure
|
||||
|
||||
End Class
|
||||
Binary file not shown.
@@ -0,0 +1,115 @@
|
||||
<%@ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001"%>
|
||||
<%
|
||||
Response.Charset = "UTF-8" '指定输出网页编码
|
||||
Server.ScriptTimeOut = 5000 '脚本执行超时最大时限
|
||||
'温馨提示:
|
||||
' 在flash的参数名upload_url中可自行定义一些参数(请求方式:POST),定义后在服务器端获取即可,比如可以应用到用户验证,文件的保存名等。
|
||||
' 如下代码在上传接口Upload.asp中定义了一个user=xxx的参数:
|
||||
' var swf = new fullAvatarEditor("swf", {
|
||||
' id: "swf",
|
||||
' upload_url: "Upload.asp?user=xxx"
|
||||
' });
|
||||
' 在本页即可用Upload.Form("user")获取xxx。
|
||||
' 本示例未作极致的用户体验与严谨的安全设计(如用户直接访问此页时该如何,万一客户端数据不可信时验证文件的大小、类型等),只保证正常情况下无误,请阁下注意。
|
||||
'艾恩ASP无组件上传类 V13.01.16
|
||||
%>
|
||||
<!--#include file="Upload.asp.cls"-->
|
||||
<%
|
||||
'生成指定长度的随机码。
|
||||
Function CreateRandomCode(ByVal Length)
|
||||
Randomize
|
||||
Dim RandCode : RandCode = ""
|
||||
Dim RandChar : RandChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
|
||||
Dim RandCharArray : RandCharArray = Split(RandChar, ",")
|
||||
Dim i
|
||||
For i = 1 To Length
|
||||
RandCode = RandCode & RandCharArray(Int(36 * Rnd))
|
||||
Next
|
||||
CreateRandomCode = RandCode
|
||||
End Function
|
||||
|
||||
Function GetVirtualPath(ByVal path)
|
||||
Dim webRoot : webRoot = Server.MapPath("/")
|
||||
Dim physicalPath : physicalPath = Server.MapPath(path)
|
||||
GetVirtualPath = Replace(physicalPath, webRoot, "")
|
||||
GetVirtualPath = Replace(GetVirtualPath, "\", "/")
|
||||
End Function
|
||||
|
||||
'取服务器时间+8位随机码作为部分文件名,确保文件名无重复。
|
||||
Dim FileName : FileName = Year(NowTime) & Right("0" & Month(NowTime), 2) & Right("0" & Day(NowTime), 2) & Right("0" & Hour(NowTime), 2) & Right("0" & Minute(NowTime), 2) & Right("0" & Second(NowTime), 2) & Left(Replace(Right(timer(), 2), ".", "") & "0", 2) & CreateRandomCode(8)
|
||||
|
||||
Dim Msg '表示自定义的附加返回消息。
|
||||
Dim Success : Success = "false" '表示图片是否已上传成功。
|
||||
Dim SavePath : SavePath = "upload" '保存在服务器的虚拟路径
|
||||
Dim SourceUrl '表示原始图片的保存地址。
|
||||
DIM AvatarUrls '表示所有头像图片的保存地址,多个之间使用英文的逗号“,”分隔。
|
||||
|
||||
Dim SuccessNum : SuccessNum = 0
|
||||
|
||||
On Error Resume Next
|
||||
'建立上传对象
|
||||
Dim Upload
|
||||
Set Upload = new AnUpLoad
|
||||
Upload.Charset = "UTF-8" '设置字符集
|
||||
Upload.Exe = "*.bmp;*.jpg;*.gif;*.png;" '设置允许上传的文件类型
|
||||
Upload.SingleSize = 1024 * 1024 * 2 '设置单个文件的最大上传限制,按字节计算,该处为2MB
|
||||
Upload.GetData()
|
||||
If Upload.ErrorID > 0 Then
|
||||
Msg = Upload.Description
|
||||
Else
|
||||
'定义一个变量用以储存当前头像的序号
|
||||
Dim AvatarNumber : AvatarNumber = 1
|
||||
Dim i : i = 1
|
||||
'遍历所有文件域
|
||||
For Each F In Upload.Files(-1)
|
||||
Dim File
|
||||
Set File = Upload.Files(F)
|
||||
If File.IsFile Then
|
||||
'如果 file 域的名称是以__source(可在插件配置参数中自定义,参数名:src_field_name)打头,说明是原始图片,如果在插件中定义可以上传的话,可在此处理。
|
||||
If InStr(File.FormName, "__source") = 1 Then
|
||||
'保存的文件名,不包括扩展名
|
||||
File.UserSetName = "asp_source_" & FileName
|
||||
'保存的文件扩展名,不含点“.”
|
||||
File.Extend = "jpg"
|
||||
'当前头像基于原图的初始化参数(即只有上传原图时才会发送该数据),用于修改头像时保证界面的视图跟保存头像时一致,提升用户体验度。
|
||||
'修改头像时设置默认加载的原图url为当前原图url+该参数即可,可直接附加到原图url中储存,不影响图片呈现。
|
||||
Dim InitParams : InitParams = Upload.Forms("__initParams")
|
||||
SourceUrl = GetVirtualPath(SavePath & "/" & File.UserSetName & "." & File.Extend) & InitParams
|
||||
If File.SaveToFile(SavePath, -1, True) Then
|
||||
SuccessNum = SuccessNum + 1
|
||||
Else
|
||||
Msg = "原图片保存失败,错误信息:" & File.Exception '错误信息请参考同目录中的PDF文件
|
||||
End If
|
||||
'否则就是头像图片(file 域的名称:__avatar1,2,3...,可在插件配置参数中自定义,参数名:avatar_field_names)
|
||||
Else
|
||||
'保存的文件名,不包括扩展名
|
||||
File.UserSetName = "asp_avatar" & AvatarNumber & "_" & FileName
|
||||
'保存的文件扩展名,不含点“.”
|
||||
File.Extend = "jpg"
|
||||
If File.SaveToFile(SavePath, -1, True) Then
|
||||
SuccessNum = SuccessNum + 1
|
||||
AvatarUrls = AvatarUrls & """" & GetVirtualPath(SavePath & "/" & File.FileName & "." & File.Extend) & ""","
|
||||
AvatarNumber = AvatarNumber + 1
|
||||
Else
|
||||
Msg = "头像保存失败,错误信息:" & File.Exception '错误信息请参考同目录中的PDF文件
|
||||
End If
|
||||
End If
|
||||
Set File = Nothing
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
'释放上传对象
|
||||
Set Upload = Nothing
|
||||
|
||||
If Err.Number <> 0 Then Err.Clear
|
||||
|
||||
If SuccessNum > 0 Then
|
||||
Success = "true"
|
||||
End If
|
||||
|
||||
If AvatarUrls <> "" Then
|
||||
AvatarUrls = Left(AvatarUrls, Len(AvatarUrls) - 1)
|
||||
End If
|
||||
'返回上传结果(json)
|
||||
Response.Write "{""success"":" & Success & ", ""msg"":""" & Msg & """, ""sourceUrl"":""" & SourceUrl & """, ""avatarUrls"":[" & AvatarUrls & "]}"
|
||||
%>
|
||||
@@ -0,0 +1,554 @@
|
||||
<%
|
||||
'=========================================================
|
||||
'Class: AnUpLoad
|
||||
'Author: Anlige
|
||||
'Version:AienAspUpload V13.12.09
|
||||
'CreationDate: 2008-04-12
|
||||
'ModificationDate: 2013-12-09
|
||||
'Homepage: http://dev.mo.cn
|
||||
'Email: zhanghuiguoanlige@126.com
|
||||
'QQ: 1034555083
|
||||
'=========================================================
|
||||
Dim StreamT
|
||||
Class AnUpLoad
|
||||
Private Form, Fils
|
||||
Private vCharSet, vMaxSize, vSingleSize, vErr, vVersion, vTotalSize, vExe, vErrExe,vboundary, vLostTime, vMode, vFileCount,StreamOpened
|
||||
private vMuti,vServerVersion
|
||||
Public Property Let Mode(ByVal value)
|
||||
vMode = value
|
||||
End Property
|
||||
|
||||
Public Property Let MaxSize(ByVal value)
|
||||
vMaxSize = value
|
||||
End Property
|
||||
|
||||
Public Property Let SingleSize(ByVal value)
|
||||
vSingleSize = value
|
||||
End Property
|
||||
|
||||
Public Property Let Exe(ByVal value)
|
||||
vExe = LCase(value)
|
||||
vExe = replace(vExe,"*.","")
|
||||
vExe = replace(vExe,";","|")
|
||||
End Property
|
||||
|
||||
Public Property Let CharSet(ByVal value)
|
||||
vCharSet = value
|
||||
End Property
|
||||
|
||||
Public Property Get ErrorID()
|
||||
ErrorID = vErr
|
||||
End Property
|
||||
|
||||
Public Property Get FileCount()
|
||||
FileCount = Fils.count
|
||||
End Property
|
||||
|
||||
Public Property Get Description()
|
||||
Description = GetErr(vErr)
|
||||
End Property
|
||||
|
||||
Public Property Get Version()
|
||||
Version = vVersion
|
||||
End Property
|
||||
|
||||
Public Property Get TotalSize()
|
||||
TotalSize = vTotalSize
|
||||
End Property
|
||||
|
||||
Public Property Get LostTime()
|
||||
LostTime = vLostTime
|
||||
End Property
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
set Form = server.createobject("Scripting.Dictionary")
|
||||
set Fils = server.createobject("Scripting.Dictionary")
|
||||
Set StreamT = server.CreateObject("Adodb.stream")
|
||||
vVersion = "AienAspUpload V13.12.09"
|
||||
vMaxSize = -1
|
||||
vSingleSize = -1
|
||||
vErr = -1
|
||||
vExe = ""
|
||||
vTotalSize = 0
|
||||
vCharSet = "gb2312"
|
||||
vMode = 0
|
||||
StreamOpened=false
|
||||
vMuti="_" & Getname() & "_"
|
||||
vServerVersion = 6.0
|
||||
Dim t_
|
||||
t_ = lcase(Request.ServerVariables("SERVER_SOFTWARE"))
|
||||
t_ = replace(t_,"microsoft-iis/","")
|
||||
if isnumeric(t_) then vServerVersion = cdbl(t_)
|
||||
End Sub
|
||||
|
||||
Private Sub Class_Terminate()
|
||||
Dim f
|
||||
Form.RemoveAll()
|
||||
For each f in Fils
|
||||
Fils(f).value=empty
|
||||
Set Fils(f) = Nothing
|
||||
Next
|
||||
Fils.RemoveAll()
|
||||
Set Form = Nothing
|
||||
Set Fils = Nothing
|
||||
if StreamOpened then StreamT.close()
|
||||
Set StreamT = Nothing
|
||||
End Sub
|
||||
|
||||
Public Sub GetData()
|
||||
Dim time1
|
||||
time1 = timer()
|
||||
Dim value, str, bcrlf, fpos, sSplit, slen, istart,ef
|
||||
Dim TotalBytes,tempdata,BytesRead,ChunkReadSize,PartSize,DataPart,formend, formhead, startpos, endpos, formname, FileName, fileExe, valueend, NewName,localname,type_1,contentType
|
||||
TotalBytes = Request.TotalBytes
|
||||
ef = false
|
||||
If checkEntryType = false Then ef = true : vErr = 2
|
||||
If vServerVersion>=6 Then
|
||||
If Not ef Then
|
||||
If vMaxSize > 0 And TotalBytes > vMaxSize Then ef = true : vErr = 1
|
||||
End If
|
||||
End If
|
||||
If ef Then Exit Sub
|
||||
If vMode = 0 Then
|
||||
vTotalSize = 0
|
||||
StreamT.Type = 1
|
||||
StreamT.Mode = 3
|
||||
StreamT.Open
|
||||
StreamOpened = true
|
||||
BytesRead = 0
|
||||
ChunkReadSize = 1024 * 16
|
||||
Do While BytesRead < TotalBytes
|
||||
PartSize = ChunkReadSize
|
||||
If PartSize + BytesRead > TotalBytes Then PartSize = TotalBytes - BytesRead
|
||||
DataPart = Request.BinaryRead(PartSize)
|
||||
StreamT.Write DataPart
|
||||
BytesRead = BytesRead + PartSize
|
||||
Loop
|
||||
StreamT.Position = 0
|
||||
tempdata = StreamT.Read
|
||||
Else
|
||||
tempdata = Request.BinaryRead(TotalBytes)
|
||||
End If
|
||||
bcrlf = ChrB(13) & ChrB(10)
|
||||
fpos = InStrB(1, tempdata, bcrlf)
|
||||
sSplit = MidB(tempdata, 1, fpos - 1)
|
||||
slen = LenB(sSplit)
|
||||
istart = slen + 2
|
||||
Do
|
||||
formend = InStrB(istart, tempdata, bcrlf & bcrlf)
|
||||
if formend<=0 then exit do
|
||||
formhead = MidB(tempdata, istart, formend - istart)
|
||||
str = Bytes2Str(formhead)
|
||||
startpos = InStr(str, "name=""") + 6
|
||||
if startpos<=0 then exit do
|
||||
endpos = InStr(startpos, str, """")
|
||||
if endpos<=0 then exit do
|
||||
formname = LCase(Mid(str, startpos, endpos - startpos))
|
||||
valueend = InStrB(formend + 3, tempdata, sSplit)
|
||||
if valueend<=0 then exit do
|
||||
If InStr(str, "filename=""") > 0 Then
|
||||
formname = formname & vMuti & "0"
|
||||
startpos = InStr(str, "filename=""") + 10
|
||||
endpos = InStr(startpos, str, """")
|
||||
type_1=instr(endpos,lcase(str),"content-type")
|
||||
contentType=trim(mid(str,type_1+13))
|
||||
FileName = Mid(str, startpos, endpos - startpos)
|
||||
If Trim(FileName) <> "" Then
|
||||
FileName = Replace(FileName, "/", "\")
|
||||
FileName = Replace(FileName, chr(0), "")
|
||||
LocalName = FileName
|
||||
FileName = Mid(FileName, InStrRev(FileName, "\") + 1)
|
||||
If instr(FileName,".")>0 Then
|
||||
fileExe = Split(FileName, ".")(UBound(Split(FileName, ".")))
|
||||
else
|
||||
fileExe = ""
|
||||
End If
|
||||
If vExe <> "" Then
|
||||
If checkExe(fileExe) = True Then
|
||||
vErr = 3
|
||||
vErrExe = fileExe
|
||||
tempdata = empty
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
NewName = Getname()
|
||||
NewName = NewName & "." & fileExe
|
||||
vTotalSize = vTotalSize + valueend - formend - 6
|
||||
If vSingleSize > 0 And (valueend - formend - 6) > vSingleSize Then
|
||||
vErr = 5
|
||||
tempdata = empty
|
||||
Exit Sub
|
||||
End If
|
||||
If vMaxSize > 0 And vTotalSize > vMaxSize Then
|
||||
vErr = 1
|
||||
tempdata = empty
|
||||
Exit Sub
|
||||
End If
|
||||
If Fils.Exists(formname) Then formname = GetNextFormName(formname)
|
||||
Dim fileCls:set fileCls= new UploadFileEx
|
||||
fileCls.ContentType=contentType
|
||||
fileCls.Size = (valueend - formend - 6)
|
||||
fileCls.Position = (formend + 3)
|
||||
fileCls.FormName = formname
|
||||
fileCls.NewName = NewName
|
||||
fileCls.FileName = FileName
|
||||
fileCls.LocalName = FileName
|
||||
fileCls.extend=split(NewName,".")(ubound(split(NewName,".")))
|
||||
Fils.Add formname, fileCls
|
||||
Set fileCls = Nothing
|
||||
End If
|
||||
Else
|
||||
value = MidB(tempdata, formend + 4, valueend - formend - 6)
|
||||
If Form.Exists(formname) Then
|
||||
Form(formname) = Form(formname) & "," & Bytes2Str(value)
|
||||
Else
|
||||
Form.Add formname, Bytes2Str(value)
|
||||
End If
|
||||
End If
|
||||
istart = valueend + 2 + slen
|
||||
Loop Until (istart + 2) >= LenB(tempdata)
|
||||
vErr = 0
|
||||
tempdata = empty
|
||||
vLostTime = FormatNumber((timer-time1)*1000,2)
|
||||
End Sub
|
||||
|
||||
Private Function CheckExe(ByVal ex)
|
||||
Dim notIn: notIn = True
|
||||
If vExe="*" then
|
||||
notIn=false
|
||||
elseIf InStr(1, vExe, "|") > 0 Then
|
||||
Dim tempExe: tempExe = Split(vExe, "|")
|
||||
Dim I: I = 0
|
||||
For I = 0 To UBound(tempExe)
|
||||
If LCase(ex) = tempExe(I) Then
|
||||
notIn = False
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
If vExe = LCase(ex) Then
|
||||
notIn = False
|
||||
End If
|
||||
End If
|
||||
checkExe = notIn
|
||||
End Function
|
||||
|
||||
Public Function GetSize(ByVal Size)
|
||||
If Size < 1024 Then
|
||||
GetSize = FormatNumber(Size, 2) & "B"
|
||||
ElseIf Size >= 1024 And Size < 1048576 Then
|
||||
GetSize = FormatNumber(Size / 1024, 2) & "KB"
|
||||
ElseIf Size >= 1048576 Then
|
||||
GetSize = FormatNumber((Size / 1024) / 1024, 2) & "MB"
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Function Bytes2Str(ByVal byt)
|
||||
If LenB(byt) = 0 Then
|
||||
Bytes2Str = ""
|
||||
Exit Function
|
||||
End If
|
||||
Dim mystream, bstr
|
||||
Set mystream =server.createobject("ADODB.Stream")
|
||||
mystream.Type = 2
|
||||
mystream.Mode = 3
|
||||
mystream.Open
|
||||
mystream.WriteText byt
|
||||
mystream.Position = 0
|
||||
mystream.CharSet = vCharSet
|
||||
mystream.Position = 2
|
||||
bstr = mystream.ReadText()
|
||||
mystream.Close
|
||||
Set mystream = Nothing
|
||||
Bytes2Str = bstr
|
||||
End Function
|
||||
|
||||
Private Function GetErr(ByVal Num)
|
||||
Select Case Num
|
||||
Case 0
|
||||
GetErr = "COMPLETE"
|
||||
Case 1
|
||||
GetErr = "ERROR_FILE_EXCEEDS_MAXSIZE_LIMIT"
|
||||
Case 2
|
||||
GetErr = "ERROR_INVALID_ENCTYPEOR_METHOD"
|
||||
Case 3
|
||||
GetErr = "ERROR_INVALID_FILETYPE(." & ucase(vErrExe) & ")"
|
||||
Case 5
|
||||
GetErr = "ERROR_FILE_EXCEEDS_SIZE_LIMIT"
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Private Function Getname()
|
||||
Dim y, m, d, h, mm, S, r
|
||||
Randomize
|
||||
y = Year(Now)
|
||||
m = right("0" & Month(Now),2)
|
||||
d = right("0" & Day(Now),2)
|
||||
h = right("0" & Hour(Now),2)
|
||||
mm =right("0" & Minute(Now),2)
|
||||
S = right("0" & Second(Now),2)
|
||||
r = CInt(Rnd() * 10000)
|
||||
r = right("0000" & r,4)
|
||||
Getname = y & m & d & h & mm & S & r
|
||||
End Function
|
||||
|
||||
Private Function checkEntryType()
|
||||
Dim ContentType, ctArray, bArray,RequestMethod
|
||||
RequestMethod=trim(LCase(Request.ServerVariables("REQUEST_METHOD")))
|
||||
if RequestMethod="" or RequestMethod<>"post" then
|
||||
checkEntryType = False
|
||||
exit function
|
||||
end if
|
||||
ContentType = LCase(Request.ServerVariables("HTTP_CONTENT_TYPE"))
|
||||
ctArray = Split(ContentType, ";")
|
||||
if ubound(ctarray)>=0 then
|
||||
If Trim(ctArray(0)) = "multipart/form-data" Then
|
||||
checkEntryType = True
|
||||
vboundary = Split(ContentType,"boundary=")(1)
|
||||
Else
|
||||
checkEntryType = False
|
||||
End If
|
||||
else
|
||||
checkEntryType = False
|
||||
end if
|
||||
End Function
|
||||
|
||||
Public Function Forms(ByVal formname)
|
||||
If trim(formname) = "-1" Then
|
||||
Set Forms = Form
|
||||
Else
|
||||
If Form.Exists(LCase(formname)) Then
|
||||
Forms = Form(LCase(formname))
|
||||
Else
|
||||
Forms = ""
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function Files(ByVal formname)
|
||||
If trim(formname) = "-1" Then
|
||||
Set Files = Fils
|
||||
Else
|
||||
dim vname
|
||||
vname = LCase(formname) & vMuti & "0"
|
||||
if instr(formname,vMuti)>0 then vname = formname
|
||||
If Fils.Exists(vname) Then
|
||||
Set Files = Fils(vname)
|
||||
Else
|
||||
Set Files = New UploadFileEmpty
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Function Files_Muti(ByVal formname,byval index)
|
||||
If trim(formname) = "-1" Then
|
||||
Set Files_Muti = Fils
|
||||
Else
|
||||
If Fils.Exists(LCase(formname) & vMuti & index) Then
|
||||
Set Files_Muti = Fils(LCase(formname) & vMuti & index)
|
||||
Else
|
||||
Set Files_Muti = New UploadFileEmpty
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
Public Function QuickSave(ByVal formname,Byval SavePath)
|
||||
Dim v, formStart,File,Result,SucceedCount
|
||||
SucceedCount = 0
|
||||
Dim TempFormName
|
||||
TempFormName = formname & vMuti
|
||||
For Each v In Fils
|
||||
If lcase(left(v,len(TempFormName))) = lcase(TempFormName) Then
|
||||
Set File = Fils(v)
|
||||
Result = File.saveToFile(SavePath,0,True)
|
||||
If Result Then SucceedCount = SucceedCount + 1
|
||||
'Set File=Nothing
|
||||
End If
|
||||
Next
|
||||
QuickSave = SucceedCount
|
||||
End Function
|
||||
|
||||
|
||||
Private Function GetNextFormName(byval formname)
|
||||
Dim formStart,currentIndex
|
||||
formStart = left(formname,instr(formname,vMuti)+len(vMuti)-1)
|
||||
currentIndex = mid(formname,instr(formname,vMuti)+len(vMuti))
|
||||
currentIndex =cint(currentIndex)
|
||||
do while Fils.Exists(formname)
|
||||
currentIndex = currentIndex + 1
|
||||
formname = formStart & currentIndex
|
||||
loop
|
||||
GetNextFormName = formname
|
||||
End Function
|
||||
End Class
|
||||
Class UploadFileEmpty
|
||||
Public Property Get IsFile()
|
||||
IsFile = false
|
||||
End Property
|
||||
End Class
|
||||
Class UploadFileEx
|
||||
Private mvarFormName , mvarNewName , mvarLocalName , mvarFileName , mvarUserSetName , mvarContentType ,mException,mvarPosition
|
||||
Private mvarSize , mvarValue , mvarPath , mvarExtend
|
||||
|
||||
Public Property Let Extend(ByVal vData )
|
||||
mvarExtend = vData
|
||||
End Property
|
||||
Public Property Get Extend()
|
||||
Extend = mvarExtend
|
||||
End Property
|
||||
|
||||
Public Property Get IsFile()
|
||||
IsFile = true
|
||||
End Property
|
||||
|
||||
Public Property Let Path(ByVal vData )
|
||||
mvarPath = vData
|
||||
End Property
|
||||
Public Property Get Path()
|
||||
Path = mvarPath
|
||||
End Property
|
||||
|
||||
Public Property Get Exception()
|
||||
Exception = mException
|
||||
End Property
|
||||
|
||||
Public Property Let Value(ByVal vData )
|
||||
mvarValue = vData
|
||||
End Property
|
||||
|
||||
Public Property Get Value()
|
||||
Value = mvarValue
|
||||
End Property
|
||||
|
||||
Public Property Let Size(ByVal vData )
|
||||
mvarSize = vData
|
||||
End Property
|
||||
Public Property Get Size()
|
||||
Size = mvarSize
|
||||
End Property
|
||||
|
||||
Public Property Let Position(ByVal vData )
|
||||
mvarPosition = vData
|
||||
End Property
|
||||
Public Property Get Position()
|
||||
Size = mvarPosition
|
||||
End Property
|
||||
|
||||
Public Property Let ContentType(ByVal vData )
|
||||
mvarContentType = vData
|
||||
End Property
|
||||
Public Property Get ContentType()
|
||||
ContentType = mvarContentType
|
||||
End Property
|
||||
|
||||
Public Property Let UserSetName(ByVal vData )
|
||||
mvarUserSetName = vData
|
||||
End Property
|
||||
Public Property Get UserSetName()
|
||||
UserSetName = mvarUserSetName
|
||||
End Property
|
||||
|
||||
Public Property Let FileName(ByVal vData )
|
||||
mvarFileName = vData
|
||||
End Property
|
||||
Public Property Get FileName()
|
||||
FileName = mvarFileName
|
||||
End Property
|
||||
|
||||
Public Property Let LocalName(ByVal vData )
|
||||
mvarLocalName = vData
|
||||
End Property
|
||||
Public Property Get LocalName()
|
||||
LocalName = mvarLocalName
|
||||
End Property
|
||||
|
||||
Public Property Let NewName(ByVal vData )
|
||||
mvarNewName = vData
|
||||
End Property
|
||||
Public Property Get NewName()
|
||||
NewName = mvarNewName
|
||||
End Property
|
||||
|
||||
Public Property Let FormName(ByVal vData )
|
||||
mvarFormName = vData
|
||||
End Property
|
||||
Public Property Get FormName()
|
||||
FormName = mvarFormName
|
||||
End Property
|
||||
|
||||
Private Sub Class_Initialize()
|
||||
mvarSize =0
|
||||
mvarFormName = ""
|
||||
End Sub
|
||||
|
||||
Public Function SaveToFile(ByVal Path , byval tOption, byval OverWrite)
|
||||
On Error Resume Next
|
||||
Dim IsP
|
||||
IsP = (InStr(Path, ":") = 2)
|
||||
If Not IsP Then Path = Server.MapPath(Path)
|
||||
Path = Replace(Path, "/", "\")
|
||||
If Mid(Path, Len(Path) - 1) <> "\" Then Path = Path + "\"
|
||||
CreateFolder Path
|
||||
mvarPath = Path
|
||||
If tOption = 1 Then
|
||||
Path = Path & mvarLocalName: mvarFileName = mvarLocalName
|
||||
Else
|
||||
If tOption = -1 And mvarUserSetName <> "" Then
|
||||
Path = Path & mvarUserSetName & "." & mvarExtend: mvarFileName = mvarUserSetName & "." & mvarExtend
|
||||
Else
|
||||
Path = Path & mvarNewName: mvarFileName = mvarNewName
|
||||
End If
|
||||
End If
|
||||
If Not OverWrite Then
|
||||
Path = GetFilePath()
|
||||
End If
|
||||
Dim tmpStrm
|
||||
Set tmpStrm =server.CreateObject("ADODB.Stream")
|
||||
tmpStrm.Mode = 3
|
||||
tmpStrm.Type = 1
|
||||
tmpStrm.Open
|
||||
StreamT.Position = mvarPosition
|
||||
StreamT.copyto tmpStrm,mvarSize
|
||||
tmpStrm.SaveToFile Path, 2
|
||||
tmpStrm.Close
|
||||
Set tmpStrm = Nothing
|
||||
'Set SaveToFile = new ErrorMessage_
|
||||
If Not Err Then
|
||||
SaveToFile = true
|
||||
Else
|
||||
SaveToFile = false
|
||||
mException=Err.Description
|
||||
End If
|
||||
End Function
|
||||
Public Function GetBytes()
|
||||
StreamT.Position = mvarPosition
|
||||
GetBytes = StreamT.read(mvarSize)
|
||||
End Function
|
||||
Private Function CreateFolder(ByVal folderPath )
|
||||
Dim oFSO
|
||||
Set oFSO = server.CreateObject("Scripting.FileSystemObject")
|
||||
Dim sParent
|
||||
sParent = oFSO.GetParentFolderName(folderPath)
|
||||
If sParent = "" Then Exit Function
|
||||
If Not oFSO.FolderExists(sParent) Then CreateFolder (sParent)
|
||||
If Not oFSO.FolderExists(folderPath) Then oFSO.CreateFolder (folderPath)
|
||||
Set oFSO = Nothing
|
||||
End Function
|
||||
|
||||
Private Function GetFilePath()
|
||||
Dim oFSO, Fname , FNameL , i
|
||||
i = 0
|
||||
Set oFSO = server.CreateObject("Scripting.FileSystemObject")
|
||||
Fname = mvarPath & mvarFileName
|
||||
FNameL = Mid(mvarFileName, 1, InStr(mvarFileName, ".") - 1)
|
||||
Do While oFSO.FileExists(Fname)
|
||||
Fname = mvarPath & FNameL & "(" & i & ")." & mvarExtend
|
||||
mvarFileName = FNameL & "(" & i & ")." & mvarExtend
|
||||
i = i + 1
|
||||
Loop
|
||||
Set oFSO = Nothing
|
||||
GetFilePath = Fname
|
||||
End Function
|
||||
End Class
|
||||
%>
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<cross-domain-policy>
|
||||
<site-control permitted-cross-domain-policies="all" />
|
||||
<allow-access-from domain="*" />
|
||||
<allow-http-request-headers-from domain="*" headers="*"/>
|
||||
</cross-domain-policy>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,138 @@
|
||||
<%--
|
||||
温馨提示:
|
||||
在flash的参数名upload_url中可自行定义一些参数(请求方式:POST),定义后在服务器端获取即可,比如可以应用到用户验证,文件的保存名等。
|
||||
本示例未作极致的用户体验与严谨的安全设计(如用户直接访问此页时该如何,万一客户端数据不可信时验证文件的大小、类型等),只保证正常情况下无误,请阁下注意。
|
||||
--%>
|
||||
<%@ page session="false" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
|
||||
<%@ page import="java.io.*"%>
|
||||
<%@ page import="java.util.*"%>
|
||||
<%@ page import="java.text.*"%>
|
||||
<%@ page import="org.apache.commons.fileupload.*"%>
|
||||
<%@ page import="org.apache.commons.fileupload.disk.*"%>
|
||||
<%@ page import="org.apache.commons.fileupload.servlet.*"%>
|
||||
<%@ page import="org.apache.commons.fileupload.util.*"%>
|
||||
<%@ page import="com.alibaba.fastjson.*"%>
|
||||
<%
|
||||
String contentType = request.getContentType();
|
||||
|
||||
if ( contentType.indexOf("multipart/form-data") >= 0 )
|
||||
{
|
||||
Result result = new Result();
|
||||
result.avatarUrls = new ArrayList();
|
||||
result.success = false;
|
||||
result.msg = "Failure!";
|
||||
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload upload = new ServletFileUpload(factory);
|
||||
FileItemIterator fileItems = upload.getItemIterator(request);
|
||||
//定义一个变量用以储存当前头像的序号
|
||||
int avatarNumber = 1;
|
||||
//取服务器时间+8位随机码作为部分文件名,确保文件名无重复。
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssS");
|
||||
String fileName = simpleDateFormat.format(new Date());
|
||||
Random random = new Random();
|
||||
String randomCode = "";
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
randomCode += Integer.toString(random.nextInt(36), 36);
|
||||
}
|
||||
fileName = fileName + randomCode;
|
||||
//基于原图的初始化参数
|
||||
String initParams = "";
|
||||
BufferedInputStream inputStream;
|
||||
BufferedOutputStream outputStream;
|
||||
//遍历表单域
|
||||
while( fileItems.hasNext() )
|
||||
{
|
||||
FileItemStream fileItem = fileItems.next();
|
||||
String fieldName = fileItem.getFieldName();
|
||||
//是否是原始图片 file 域的名称(默认的 file 域的名称是__source,可在插件配置参数中自定义。参数名:src_field_name)
|
||||
Boolean isSourcePic = fieldName.equals("__source");
|
||||
//文件名,如果是本地或网络图片为原始文件名(不含扩展名)、如果是摄像头拍照则为 *FromWebcam
|
||||
//String name = fileItem.getName();
|
||||
//当前头像基于原图的初始化参数(即只有上传原图时才会发送该数据),用于修改头像时保证界面的视图跟保存头像时一致,提升用户体验度。
|
||||
//修改头像时设置默认加载的原图url为当前原图url+该参数即可,可直接附加到原图url中储存,不影响图片呈现。
|
||||
if ( fieldName.equals("__initParams") )
|
||||
{
|
||||
inputStream = new BufferedInputStream(fileItem.openStream());
|
||||
byte[] bytes = new byte [inputStream.available()];
|
||||
inputStream.read(bytes);
|
||||
initParams = new String(bytes, "UTF-8");
|
||||
inputStream.close();
|
||||
}
|
||||
//如果是原始图片 file 域的名称或者以默认的头像域名称的部分“__avatar”打头
|
||||
else if ( isSourcePic || fieldName.startsWith("__avatar") )
|
||||
{
|
||||
String virtualPath = "/upload/jsp_avatar" + avatarNumber + "_" + fileName + ".jpg";
|
||||
//原始图片(默认的 file 域的名称是__source,可在插件配置参数中自定义。参数名:src_field_name)。
|
||||
if( isSourcePic )
|
||||
{
|
||||
result.sourceUrl = virtualPath = "/upload/jsp_source_" + fileName + ".jpg";
|
||||
}
|
||||
//头像图片(默认的 file 域的名称:__avatar1,2,3...,可在插件配置参数中自定义,参数名:avatar_field_names)。
|
||||
else
|
||||
{
|
||||
result.avatarUrls.add(virtualPath);
|
||||
avatarNumber++;
|
||||
}
|
||||
inputStream = new BufferedInputStream(fileItem.openStream());
|
||||
outputStream = new BufferedOutputStream(new FileOutputStream(application.getRealPath("/") + virtualPath.replace("/", "\\")));
|
||||
Streams.copy(inputStream, outputStream, true);
|
||||
inputStream.close();
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
/*else
|
||||
{
|
||||
附加在接口中的其他参数...
|
||||
如下代码在上传接口upload.jsp中定义了一个user=xxx的参数:
|
||||
var swf = new fullAvatarEditor("swf", {
|
||||
id: "swf",
|
||||
upload_url: "Upload.asp?user=xxx"
|
||||
});
|
||||
即可如下获取user的值xxx
|
||||
|
||||
inputStream = new BufferedInputStream(fileItem.openStream());
|
||||
byte[] bytes = new byte [inputStream.available()];
|
||||
inputStream.read(bytes);
|
||||
String user = new String(bytes, "UTF-8");
|
||||
inputStream.close();
|
||||
}*/
|
||||
}
|
||||
if ( result.sourceUrl != null )
|
||||
{
|
||||
result.sourceUrl += initParams;
|
||||
}
|
||||
result.success = true;
|
||||
result.msg = "Success!";
|
||||
/*
|
||||
To Do...可在此处处理储存事项
|
||||
*/
|
||||
//返回图片的保存结果(返回内容为json字符串,可自行构造,该处使用fastjson构造)
|
||||
out.println(JSON.toJSONString(result));
|
||||
}
|
||||
%>
|
||||
<%!
|
||||
/**
|
||||
* 表示上传的结果。
|
||||
*/
|
||||
private class Result
|
||||
{
|
||||
/**
|
||||
* 表示图片是否已上传成功。
|
||||
*/
|
||||
public Boolean success;
|
||||
/**
|
||||
* 自定义的附加消息。
|
||||
*/
|
||||
public String msg;
|
||||
/**
|
||||
* 表示原始图片的保存地址。
|
||||
*/
|
||||
public String sourceUrl;
|
||||
/**
|
||||
* 表示所有头像图片的保存地址,该变量为一个数组。
|
||||
*/
|
||||
public ArrayList avatarUrls;
|
||||
}
|
||||
%>
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/* 温馨提示:
|
||||
* 在flash的参数名upload_url中可自行定义一些参数(请求方式:GET),定义后在服务器端获取即可,比如可以应用到用户验证,文件的保存名等。
|
||||
* 本示例未作极致的用户体验与严谨的安全设计(如用户直接访问此页时该如何,万一客户端数据不可信时验证文件的大小、类型等),只保证正常情况下无误,请阁下注意。
|
||||
*/
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
$result = array();
|
||||
$result['success'] = false;
|
||||
$successNum = 0;
|
||||
//定义一个变量用以储存当前头像的序号
|
||||
$avatarNumber = 1;
|
||||
$i = 0;
|
||||
$msg = '';
|
||||
//上传目录
|
||||
$dir = "upload";
|
||||
//遍历所有文件域
|
||||
while (list($key, $val) = each($_FILES))
|
||||
{
|
||||
if ( $_FILES[$key]['error'] > 0)
|
||||
{
|
||||
$msg .= $_FILES[$key]['error'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$fileName = date("YmdHis").'_'.floor(microtime() * 1000).'_'.createRandomCode(8);
|
||||
//处理原始图片(默认的 file 域的名称是__source,可在插件配置参数中自定义。参数名:src_field_name)
|
||||
//如果在插件中定义可以上传原始图片的话,可在此处理,否则可以忽略。
|
||||
if ($key == '__source')
|
||||
{
|
||||
//当前头像基于原图的初始化参数,用于修改头像时保证界面的视图跟保存头像时一致。帮助提升用户体验度。修改头像时设置默认加载的原图的url为此图片的url+该参数即可。
|
||||
$initParams = $_POST["__initParams"];
|
||||
$virtualPath = "$dir/php_source_$fileName.jpg";
|
||||
$result['sourceUrl'] = '/' . $virtualPath.$initParams;
|
||||
move_uploaded_file($_FILES[$key]["tmp_name"], $virtualPath);
|
||||
/*
|
||||
可在此将 $result['sourceUrl'] 储存到数据库
|
||||
*/
|
||||
$successNum++;
|
||||
}
|
||||
//处理头像图片(默认的 file 域的名称:__avatar1,2,3...,可在插件配置参数中自定义,参数名:avatar_field_names)
|
||||
else if (strpos($key, '__avatar') === 0)
|
||||
{
|
||||
$virtualPath = "$dir/php_avatar" . $avatarNumber . "_$fileName.jpg";
|
||||
$result['avatarUrls'][$i] = '/' . $virtualPath;
|
||||
move_uploaded_file($_FILES[$key]["tmp_name"], $virtualPath);
|
||||
/*
|
||||
可在此将 $result['avatarUrls'][$i] 储存到数据库
|
||||
*/
|
||||
$successNum++;
|
||||
$i++;
|
||||
}
|
||||
/*
|
||||
else
|
||||
{
|
||||
如下代码在上传接口upload.php中定义了一个user=xxx的参数:
|
||||
var swf = new fullAvatarEditor("swf", {
|
||||
id: "swf",
|
||||
upload_url: "Upload.php?user=xxx"
|
||||
});
|
||||
在此即可用$_POST["user"]获取xxx。
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
$result['msg'] = $msg;
|
||||
if ($successNum > 0)
|
||||
{
|
||||
$result['success'] = true;
|
||||
}
|
||||
//返回图片的保存结果(返回内容为json字符串)
|
||||
print json_encode($result);
|
||||
|
||||
/**************************************************************
|
||||
* 生成指定长度的随机码。
|
||||
* @param int $length 随机码的长度。
|
||||
* @access public
|
||||
**************************************************************/
|
||||
function createRandomCode($length)
|
||||
{
|
||||
$randomCode = "";
|
||||
$randomChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$randomCode .= $randomChars { mt_rand(0, 35) };
|
||||
}
|
||||
return $randomCode;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,89 @@
|
||||
function fullAvatarEditor() {
|
||||
var id = 'fullAvatarEditor' //flash文件的ID
|
||||
var file = 'plugins/fullavatareditor/fullAvatarEditor.swf'; //flash文件的路径
|
||||
var version = "10.1.0"; //播放该flash所需的最低版本
|
||||
var expressInstall = 'expressInstall.swf'; //expressInstall.swf的路径
|
||||
var width = 600; //flash文件的宽度
|
||||
var height = 430; //flash文件的高度
|
||||
var container = id; //装载flash文件的容器(如div)的id
|
||||
var flashvars = {};
|
||||
var callback = function(){};
|
||||
var heightChanged = false;
|
||||
//智能获取参数,字符类型为装载flash文件的容器(如div)的id,第一个数字类型的为高度,第二个为宽度,第一个object类型的为参数对象,如此4个参数的顺序可随意。
|
||||
for(var i = 0; i < arguments.length; i++)
|
||||
{
|
||||
if(typeof arguments[i] == 'string')
|
||||
{
|
||||
container = arguments[i];
|
||||
}
|
||||
else if(typeof arguments[i] == 'number')
|
||||
{
|
||||
if(heightChanged)
|
||||
{
|
||||
width = arguments[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
height = arguments[i];
|
||||
heightChanged = true;
|
||||
}
|
||||
}
|
||||
else if(typeof arguments[i] == 'function')
|
||||
{
|
||||
callback = arguments[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
flashvars = arguments[i];
|
||||
}
|
||||
}
|
||||
var vars = {
|
||||
id : id
|
||||
};
|
||||
//合并参数
|
||||
for (var name in flashvars)
|
||||
{
|
||||
if(flashvars[name] != null)
|
||||
{
|
||||
if(name == 'upload_url' || name == 'src_url')
|
||||
{
|
||||
vars[name] = encodeURIComponent(flashvars[name]);
|
||||
}
|
||||
else
|
||||
{
|
||||
vars[name] = flashvars[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
var params = {
|
||||
menu : 'true',
|
||||
scale : 'noScale',
|
||||
allowFullscreen : 'true',
|
||||
allowScriptAccess : 'always',
|
||||
wmode : 'transparent'
|
||||
};
|
||||
var attributes = {
|
||||
id : vars.id,
|
||||
name: vars.id
|
||||
};
|
||||
var swf = null;
|
||||
var callbackFn = function (e) {
|
||||
swf = e.ref;
|
||||
swf.eventHandler = function(json){
|
||||
callback.call(swf, json);
|
||||
};
|
||||
};
|
||||
swfobject.embedSWF(
|
||||
file,
|
||||
container,
|
||||
width,
|
||||
height,
|
||||
version,
|
||||
expressInstall,
|
||||
vars,
|
||||
params,
|
||||
attributes,
|
||||
callbackFn
|
||||
);
|
||||
return swf;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* Cookie plugin
|
||||
*
|
||||
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
|
||||
* Dual licensed under the MIT and GPL licenses:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a Cookie with the given name and value and other optional parameters.
|
||||
*
|
||||
* @example $.Cookie('the_cookie', 'the_value');
|
||||
* @desc Set the value of a Cookie.
|
||||
* @example $.Cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
|
||||
* @desc Create a Cookie with all available options.
|
||||
* @example $.Cookie('the_cookie', 'the_value');
|
||||
* @desc Create a session Cookie.
|
||||
* @example $.Cookie('the_cookie', null);
|
||||
* @desc Delete a Cookie by passing null as value. Keep in mind that you have to use the same path and domain
|
||||
* used when the Cookie was set.
|
||||
*
|
||||
* @param String name The name of the Cookie.
|
||||
* @param String value The value of the Cookie.
|
||||
* @param Object options An object literal containing key/value pairs to provide optional Cookie attributes.
|
||||
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
|
||||
* If a negative value is specified (e.g. a date in the past), the Cookie will be deleted.
|
||||
* If set to null or omitted, the Cookie will be a session Cookie and will not be retained
|
||||
* when the the browser exits.
|
||||
* @option String path The value of the path atribute of the Cookie (default: path of page that created the Cookie).
|
||||
* @option String domain The value of the domain attribute of the Cookie (default: domain of page that created the Cookie).
|
||||
* @option Boolean secure If true, the secure attribute of the Cookie will be set and the Cookie transmission will
|
||||
* require a secure protocol (like HTTPS).
|
||||
* @type undefined
|
||||
*
|
||||
* @name $.Cookie
|
||||
* @cat Plugins/Cookie
|
||||
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the value of a Cookie with the given name.
|
||||
*
|
||||
* @example $.Cookie('the_cookie');
|
||||
* @desc Get the value of a Cookie.
|
||||
*
|
||||
* @param String name The name of the Cookie.
|
||||
* @return The value of the Cookie.
|
||||
* @type String
|
||||
*
|
||||
* @name $.Cookie
|
||||
* @cat Plugins/Cookie
|
||||
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
||||
*/
|
||||
$.Cookie = function(name, value, options) {
|
||||
if (typeof value != 'undefined') { // name and value given, set Cookie
|
||||
options = options || {};
|
||||
if (value === null) {
|
||||
value = '';
|
||||
options.expires = -1;
|
||||
}
|
||||
var expires = '';
|
||||
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
||||
var date;
|
||||
if (typeof options.expires == 'number') {
|
||||
date = new Date();
|
||||
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
||||
} else {
|
||||
date = options.expires;
|
||||
}
|
||||
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
|
||||
}
|
||||
// CAUTION: Needed to parenthesize options.path and options.domain
|
||||
// in the following expressions, otherwise they evaluate to undefined
|
||||
// in the packed version for some reason...
|
||||
var path = options.path ? '; path=' + (options.path) : '';
|
||||
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
||||
var secure = options.secure ? '; secure' : '';
|
||||
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
||||
} else { // only name given, get Cookie
|
||||
var cookieValue = null;
|
||||
if (document.cookie && document.cookie != '') {
|
||||
var cookies = document.cookie.split(';');
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
var cookie = jQuery.trim(cookies[i]);
|
||||
// Does this cookie string begin with the name we want?
|
||||
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,80 @@
|
||||
(function($){
|
||||
var O = 'opacity',
|
||||
C = 'CursorMove',
|
||||
M = 'mousemove.drag',
|
||||
U = 'mouseup.drag',
|
||||
D = 'mousedown.drag',
|
||||
W = $(window),
|
||||
A = $(document),
|
||||
timer = null,
|
||||
E = function () {
|
||||
this.w.css(O, 1);
|
||||
A.unbind(M+' '+U);
|
||||
},
|
||||
G = function (e) {
|
||||
var m = this,
|
||||
p = m.w.offset(),
|
||||
t = p.top,
|
||||
l = p.left,
|
||||
r = W.width() - m.w.outerWidth(),
|
||||
b = W.height() - m.w.outerHeight(),
|
||||
X = e.pageX,
|
||||
Y = e.pageY,
|
||||
x = m.p.left + (X - m.x) - W.scrollLeft(),
|
||||
y = m.p.top + (Y - m.y) - W.scrollTop();
|
||||
//以下逻辑保证在可视范围内移动
|
||||
if (l <= 0 && X < m.x)
|
||||
{
|
||||
x = 0;
|
||||
m.x = Math.max(X, 0);
|
||||
m.p.left = 0;
|
||||
}
|
||||
if (t <= 0 && Y < m.y)
|
||||
{
|
||||
y = 0;
|
||||
m.y = Math.max(Y, 0);
|
||||
m.p.top = 0;
|
||||
}
|
||||
if (r <= l - A.scrollLeft() && X > m.x)
|
||||
{
|
||||
x = r;
|
||||
m.x = Math.min(X, r);
|
||||
m.p.left = r;
|
||||
}
|
||||
if (b <= t - A.scrollLeft() && Y > m.y)
|
||||
{
|
||||
y = b;
|
||||
m.y = Math.min(Y, b);
|
||||
m.p.top = b;
|
||||
}
|
||||
m.w.css({ left : x, top : y });
|
||||
return false;
|
||||
},
|
||||
S = function (e, m) {
|
||||
e.preventDefault();
|
||||
m = this;
|
||||
m.w.css(O, 0.8);
|
||||
m.p = m.w.offset();
|
||||
m.x = e.pageX;
|
||||
m.y = e.pageY;
|
||||
A.bind(M, $.proxy(G, m)).bind(U, $.proxy(E, m));
|
||||
};
|
||||
$.fn.Drag = function(o){
|
||||
return this.each(function () {
|
||||
var e = $(this),
|
||||
x = function () {
|
||||
this.h = o ? (typeof o === 'string' ? $(o, e[0]) : o) : e;
|
||||
this.w = e;
|
||||
return this;
|
||||
},
|
||||
X = new x();
|
||||
e.data('__h', X.h);
|
||||
X.h.addClass(C).unbind(D).bind(D, $.proxy(S, X));
|
||||
});
|
||||
};
|
||||
$.fn.unDrag = function () {
|
||||
return this.each(function(){
|
||||
($(this).data('__h') || $()).removeClass(C).unbind(D);
|
||||
});
|
||||
};
|
||||
})($);
|
||||
@@ -0,0 +1,109 @@
|
||||
(function($){
|
||||
var doc = $(document),
|
||||
win = $(window),
|
||||
mouseDown = 'mousedown.resize',
|
||||
mouseMove = 'mousemove.resize',
|
||||
mouseUp = 'mouseup.resize',
|
||||
clsName = 'CursorResize',
|
||||
resize = function (e) {
|
||||
var o = this,
|
||||
a = o.wrapper.width('auto'),
|
||||
b = o.target,
|
||||
c = 0,
|
||||
d = 0,
|
||||
f = b.offset();
|
||||
if (a)
|
||||
{
|
||||
c = a.width() - b.width();
|
||||
d = a.height() - b.height();
|
||||
f = a.offset();
|
||||
}
|
||||
var m = $.extend({
|
||||
width : win.width() - (f.left - doc.scrollLeft()) - c,
|
||||
height : win.height() - (f.top - doc.scrollTop()) - d
|
||||
}, o.max),
|
||||
w = Math.min(Math.max(e.pageX - o.x + o.w, o.min.width), m.width),
|
||||
h = Math.min(Math.max(e.pageY - o.y + o.h, o.min.height),m.height);
|
||||
b.css({ width : w, height : h });
|
||||
return false;
|
||||
},
|
||||
end = function () {
|
||||
doc.unbind(mouseMove + ' ' + mouseUp);
|
||||
},
|
||||
start = function (e) {
|
||||
var E = this,
|
||||
T = E.target;
|
||||
E.x = e.pageX;
|
||||
E.y = e.pageY;
|
||||
E.w = T.outerWidth() - T.getPadding().w;
|
||||
E.h = T.outerHeight() - T.getPadding().h;
|
||||
if (E.min.width === 0)
|
||||
{
|
||||
var MW = T.data('_mw');
|
||||
if (MW)
|
||||
{
|
||||
E.min.width = MW;
|
||||
}
|
||||
else
|
||||
{
|
||||
E.min.width = T.outerWidth() - T.getPadding().w;
|
||||
T.data('_mw', E.min.width);
|
||||
}
|
||||
}
|
||||
if (this.min.height === 0)
|
||||
{
|
||||
var MH = T.data('_mh');
|
||||
if (MH)
|
||||
{
|
||||
E.min.height = MH;
|
||||
}
|
||||
else
|
||||
{
|
||||
E.min.height = T.outerHeight() - T.getPadding().h;
|
||||
T.data('_mh', E.min.height);
|
||||
}
|
||||
}
|
||||
doc.bind(mouseMove, $.proxy(resize, E)).bind(mouseUp, end);
|
||||
return false;
|
||||
};
|
||||
$.fn.resize = function(o){
|
||||
o = $.extend({ min : { width : 0, height: 0 }}, o);
|
||||
/*
|
||||
options = {
|
||||
handler : null,
|
||||
wrapper : null,
|
||||
min : { width : 0, height: 0},
|
||||
max : { width : 0, height: 0}
|
||||
};
|
||||
*/
|
||||
return this.each(function(){
|
||||
var e = $(this),
|
||||
x = function () {
|
||||
this.target = e;
|
||||
this.handler = o.handler ? (typeof o.handler === 'string' ? $(o.handler, e[0]) : o.handler) : e;
|
||||
this.wrapper = o.wrapper;
|
||||
e.data('_h', this.handler);
|
||||
this.min = o.min;
|
||||
this.max = o.max;
|
||||
if (o.min) $.extend(this.min, o.min);
|
||||
return this;
|
||||
},
|
||||
X = new x();
|
||||
X.handler.addClass(clsName).unbind(mouseDown).bind(mouseDown, $.proxy(start, X));
|
||||
});
|
||||
};
|
||||
$.fn.unResize = function () {
|
||||
return this.each(function(){
|
||||
($(this).data('_h') || $()).removeClass(clsName).unbind(mouseDown);
|
||||
});
|
||||
};
|
||||
$.fn.getPadding = function () {
|
||||
var s = this[0].style,
|
||||
o =
|
||||
{
|
||||
w : parseInt(s.paddingLeft) + parseInt(s.paddingRight) || 0,
|
||||
h : parseInt(s.paddingTop) + parseInt(s.paddingBottom) || 0
|
||||
};
|
||||
return o;
|
||||
};
|
||||
})($);
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,231 @@
|
||||
swfobject.addDomLoadEvent(function () {
|
||||
//------------------------------------------------------------------------------示例一
|
||||
var webcamAvailable = false;
|
||||
var currentTab = 'upload';
|
||||
var sourcePic1Url = $.Cookie('swf1');
|
||||
var sourcePic2Url = $.Cookie('swf2');
|
||||
if(sourcePic2Url == null)
|
||||
{
|
||||
sourcePic2Url = "http://www.baidu.com/img/bdlogo.png";
|
||||
}
|
||||
var callback = function (json) {
|
||||
var id = this.id;
|
||||
switch (json.code) {
|
||||
case 2:
|
||||
//如果加载原图成功,说明进入了编辑面板,显示保存和取消按钮,隐藏拍照按钮
|
||||
if (json.type == 0) {
|
||||
if(id == "swf1")
|
||||
{
|
||||
$('#webcamPanelButton').hide();
|
||||
$('#editorPanelButtons').show();
|
||||
}
|
||||
}
|
||||
//否则会转到上传面板
|
||||
else {
|
||||
//隐藏所有按钮
|
||||
if(id == "swf1")$('#editorPanelButtons,#webcamPanelButton').hide();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
//如果摄像头已准备就绪且用户已允许使用,显示拍照按钮。
|
||||
if (json.type == 0) {
|
||||
if(id == "swf1")
|
||||
{
|
||||
$('.button_shutter').removeClass('Disabled');
|
||||
$('#webcamPanelButton').show();
|
||||
webcamAvailable = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(id == "swf1")
|
||||
{
|
||||
webcamAvailable = false;
|
||||
$('#webcamPanelButton').hide();
|
||||
}
|
||||
//如果摄像头已准备就绪但用户已拒绝使用。
|
||||
if (json.type == 1) {
|
||||
alert('用户拒绝使用摄像头!');
|
||||
}
|
||||
//如果摄像头已准备就绪但摄像头被占用。
|
||||
else {
|
||||
alert('摄像头被占用!');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
alert("您选择的原图片文件大小(" + json.content + ")超出了指定的值(2MB)。");
|
||||
break;
|
||||
case 5:
|
||||
//如果上传成功
|
||||
if (json.type == 0) {
|
||||
var e = this;
|
||||
var html = $('<div class="imgList"/>');
|
||||
for(var i = 0; i < json.content.avatarUrls.length; i++)
|
||||
{
|
||||
html.append('<dl><dt>头像图片'+(i+1)+'</dt><dd><img src="' + json.content.avatarUrls[i] + '" /></dd></dl>');
|
||||
}
|
||||
var button = [];
|
||||
//如果上传了原图,给个修改按钮,感受视图初始化带来的用户体验度提升
|
||||
if(json.content.sourceUrl)
|
||||
{
|
||||
button.push({text : '修改头像', callback:function(){
|
||||
this.close();
|
||||
$.Cookie(id, json.content.sourceUrl);
|
||||
location.reload();
|
||||
//e.call('loadPic', json.content.sourceUrl);
|
||||
}});
|
||||
}
|
||||
else
|
||||
{
|
||||
$.Cookie(id, null);
|
||||
}
|
||||
button.push({text : '关闭窗口'});
|
||||
$.dialog({
|
||||
title:'图片已成功保存至服务器',
|
||||
content:html,
|
||||
button:button,
|
||||
mask:true,
|
||||
draggable:false
|
||||
});
|
||||
}
|
||||
else {
|
||||
alert(json.type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
var swf1 = new fullAvatarEditor('swf1', 335, {
|
||||
id : 'swf1',
|
||||
upload_url : 'upload.php',
|
||||
src_url : sourcePic1Url, //默认加载的原图片的url
|
||||
tab_visible : false, //不显示选项卡,外部自定义
|
||||
button_visible : false, //不显示按钮,外部自定义
|
||||
src_upload : 2, //是否上传原图片的选项:2-显示复选框由用户选择,0-不上传,1-上传
|
||||
checkbox_visible : false, //不显示复选框,外部自定义
|
||||
browse_box_align : 38, //图片选择框的水平对齐方式。left:左对齐;center:居中对齐;right:右对齐;数值:相对于舞台的x坐标
|
||||
webcam_box_align : 38, //摄像头拍照框的水平对齐方式,如上。
|
||||
avatar_sizes : '258*200', //定义单个头像
|
||||
avatar_sizes_desc :'258*200像素', //头像尺寸的提示文本。
|
||||
browse_box_align:'left', //头像选择框对齐方式
|
||||
webcam_box_align:'left', //头像拍照框对齐方式
|
||||
//头像简介
|
||||
avatar_intro : ' 最终会生成下面这个尺寸的头像',
|
||||
avatar_tools_visible:true //是否显示颜色调整工具
|
||||
}, callback);
|
||||
//选项卡点击事件
|
||||
$('#avatar-tab li').click(function () {
|
||||
if (currentTab != this.id) {
|
||||
currentTab = this.id;
|
||||
$(this).addClass('active');
|
||||
$(this).siblings().removeClass('active');
|
||||
//如果是点击“相册选取”
|
||||
if (this.id === 'albums') {
|
||||
//隐藏flash
|
||||
hideSWF();
|
||||
showAlbums();
|
||||
}
|
||||
else {
|
||||
hideAlbums();
|
||||
showSWF();
|
||||
if (this.id === 'webcam') {
|
||||
$('#editorPanelButtons').hide();
|
||||
if (webcamAvailable) {
|
||||
$('.button_shutter').removeClass('Disabled');
|
||||
$('#webcamPanelButton').show();
|
||||
}
|
||||
}
|
||||
else {
|
||||
//隐藏所有按钮
|
||||
$('#editorPanelButtons,#webcamPanelButton').hide();
|
||||
}
|
||||
}
|
||||
swf1.call('changepanel', this.id);
|
||||
}
|
||||
});
|
||||
//复选框事件
|
||||
$('#src_upload').change(function () {
|
||||
swf1.call('srcUpload', this.checked);
|
||||
});
|
||||
//点击上传按钮的事件
|
||||
$('.button_upload').click(function () {
|
||||
swf1.call('upload');
|
||||
});
|
||||
//点击取消按钮的事件
|
||||
$('.button_cancel').click(function () {
|
||||
var activedTab = $('#avatar-tab li.active')[0].id;
|
||||
if (activedTab === 'albums') {
|
||||
hideSWF();
|
||||
showAlbums();
|
||||
}
|
||||
else {
|
||||
swf1.call('changepanel', activedTab);
|
||||
if (activedTab === 'webcam') {
|
||||
$('#editorPanelButtons').hide();
|
||||
if (webcamAvailable) {
|
||||
$('.button_shutter').removeClass('Disabled');
|
||||
$('#webcamPanelButton').show();
|
||||
}
|
||||
}
|
||||
else {
|
||||
//隐藏所有按钮
|
||||
$('#editorPanelButtons,#webcamPanelButton').hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
//点击拍照按钮的事件
|
||||
$('.button_shutter').click(function () {
|
||||
if (!$(this).hasClass('Disabled')) {
|
||||
$(this).addClass('Disabled');
|
||||
swf1.call('pressShutter');
|
||||
}
|
||||
});
|
||||
//从相册中选取
|
||||
$('#userAlbums a').click(function () {
|
||||
var sourcePic = this.href;
|
||||
swf1.call('loadPic', sourcePic);
|
||||
//隐藏相册
|
||||
hideAlbums();
|
||||
//显示flash
|
||||
showSWF();
|
||||
return false;
|
||||
});
|
||||
//隐藏flash的函数
|
||||
function hideSWF() {
|
||||
//将宽高设置为0的方式来隐藏flash,而不能使用将其display样式设置为none的方式来隐藏,否则flash将不会被加载,隐藏时储存其宽高,以便后期恢复
|
||||
$('#flash1').data({
|
||||
w: $('#flash1').width(),
|
||||
h: $('#flash1').height()
|
||||
})
|
||||
.css({
|
||||
width: '0px',
|
||||
height: '0px',
|
||||
overflow: 'hidden'
|
||||
});
|
||||
//隐藏所有按钮
|
||||
$('#editorPanelButtons,#webcamPanelButton').hide();
|
||||
}
|
||||
function showSWF() {
|
||||
$('#flash1').css({
|
||||
width: $('#flash1').data('w'),
|
||||
height: $('#flash1').data('h')
|
||||
});
|
||||
}
|
||||
//显示相册的函数
|
||||
function showAlbums() {
|
||||
$('#userAlbums').show();
|
||||
}
|
||||
//隐藏相册的函数
|
||||
function hideAlbums() {
|
||||
$('#userAlbums').hide();
|
||||
}
|
||||
//------------------------------------------------------------------------------示例二
|
||||
var swf2 = new fullAvatarEditor('swf2', {
|
||||
id: 'swf2',
|
||||
upload_url: 'upload.php', //上传图片的接口地址
|
||||
src_url: sourcePic2Url, //默认加载的原图片的url
|
||||
src_upload: 2, //是否上传原图片的选项:2-显示复选框由用户选择,0-不上传,1-上传
|
||||
avatar_scale:2, //头像保存时的缩放系数
|
||||
avatar_intro:'最终头像的尺寸为以下尺寸 * 2(设置的缩放系数)', //头像尺寸的提示文本。其间用"|"号分隔,
|
||||
avatar_sizes_desc:'100*100像素,缩放系数为2,保存后的大小为200*200像素。|50*50像素,缩放系数为2,保存后的大小为100*100像素。|32*32像素,缩放系数为2,保存后的大小为64*64像素。'
|
||||
}, callback);
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Simple demo</title>
|
||||
<script type="text/javascript" src="scripts/swfobject.js"></script>
|
||||
<script type="text/javascript" src="scripts/fullAvatarEditor.js"></script>
|
||||
</head>
|
||||
<body class="gray-bg">
|
||||
<div style="width:630px;margin: 0 auto;">
|
||||
<h1 style="text-align:center">富头像上传编辑器演示</h1>
|
||||
<div>
|
||||
<p id="swfContainer">
|
||||
本组件需要安装Flash Player后才可使用,请从<a href="http://www.adobe.com/go/getflashplayer">这里</a>下载安装。
|
||||
</p>
|
||||
</div>
|
||||
<p style="text-align:center"><button type="button" id="upload">自定义上传按钮</button></p>
|
||||
<p style="text-align:center">提示:本演示使用的上传接口类型为ASP,如要测试上传,请在服务器环境中演示,更多演示请看<a href="http://www.fullavatareditor.com/demo.html">http://www.fullavatareditor.com/demo.html</a></p>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
swfobject.addDomLoadEvent(function () {
|
||||
var swf = new fullAvatarEditor("swfContainer", {
|
||||
id: 'swf',
|
||||
upload_url: 'asp/Upload.asp',
|
||||
src_upload:2
|
||||
}, function (msg) {
|
||||
switch(msg.code)
|
||||
{
|
||||
case 1 : alert("页面成功加载了组件!");break;
|
||||
case 2 : alert("已成功加载默认指定的图片到编辑面板。");break;
|
||||
case 3 :
|
||||
if(msg.type == 0)
|
||||
{
|
||||
alert("摄像头已准备就绪且用户已允许使用。");
|
||||
}
|
||||
else if(msg.type == 1)
|
||||
{
|
||||
alert("摄像头已准备就绪但用户未允许使用!");
|
||||
}
|
||||
else
|
||||
{
|
||||
alert("摄像头被占用!");
|
||||
}
|
||||
break;
|
||||
case 5 :
|
||||
if(msg.type == 0)
|
||||
{
|
||||
if(msg.content.sourceUrl)
|
||||
{
|
||||
alert("原图已成功保存至服务器,url为:\n" + msg.content.sourceUrl);
|
||||
}
|
||||
alert("头像已成功保存至服务器,url为:\n" + msg.content.avatarUrls.join("\n"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
);
|
||||
document.getElementById("upload").onclick=function(){
|
||||
swf.call("upload");
|
||||
};
|
||||
});
|
||||
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
|
||||
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F5f036dd99455cb8adc9de73e2f052f72' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user