下载最新的zip压缩包 http://www.uploadify.com
导入default.css,uploadify.css,jQuery脚本,swfobject脚本和Uploadify插件。并且添加调用插件使用$,在您的网页的<head>部分ready事件:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#uploadify").uploadify({
'uploader': 'uploadify.allglyphs.swf',
'script': 'http://www.cnblogs.com/Service/uploadXsNetshopHuxing.ashx',
'cancelImg': 'cancel.png',
'folder': 'UploadFile',
'queueID': 'fileQueue',
'auto': false,
'scriptData':{'houseID':'<%= intHouseID %>','houseType':1},
'fileExt':'*.jpg;*.gif',
'fileDesc':'请选择jpg或gif文件格式',
'fileDataName': 'imgpreview',
'multi': false,
'sizeLimit':1000000,
'onComplete':function(event,queueId,fileObj,response,data)
{
$("#uploadbtn1").html("<img src='"+fileObj.filePath+"' width='600px' />");
}
// 'uploader': 'uploadify.allglyphs.swf',
// 'cancelImg': 'cancel.png',
// 'script': 'uploadfile.asp',
// 'multi': true,
// 'buttonText': 'Browse',
// 'displayData': 'speed',
// 'simUploadLimit': 2,
// 'fileDataName': 'imgpreview'
});
$("#uploadify2").uploadify({
'uploader': 'uploadify.allglyphs.swf',
'script': 'http://www.cnblogs.com/Service/uploadXsNetshopHuxing.ashx',
'cancelImg': 'cancel.png',
'folder': 'UploadFile',
'queueID': 'fileQueue2',
'scriptData':{'houseID':'<%= intHouseID %>','houseType':2},
'auto': false,
'fileExt':'*.jpg;*.gif',
'fileDesc':'请选择jpg或gif文件格式',
'fileDataName': 'imgpreview',
'multi': true,
'queueSizeLimit':'2',
'sizeLimit':1000000,
'onAllComplete':function()
{
$("#uploadbtn2").fadeOut(250);
},
'onComplete':function(event, ID, fileObj, response, data)
{
$("#loadImage").append("<img src='"+fileObj.filePath+"' width='600px' />");
}
});
}
);
</script>
后台处理:
public class uploadXsNetshopHuxing : IHttpHandler
{
PhotoHelper photoHelper = new PhotoHelper();
bllXsHouseImages bllImage = new bllXsHouseImages();
public void ProcessRequest(HttpContext context)
{
context.Response.Charset = "utf-8";
context.Response.ContentType = "text/plain";
HttpPostedFile file = context.Request.Files["imgpreview"];
int HouseType = Convert.ToInt32(context.Request.Params["houseType"]);
int HouseID = Convert.ToInt32(context.Request.Params["houseID"]);
string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"])+"\\";
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string filename = file.FileName;// +;
int dot = filename.IndexOf('.');
filename = filename.Substring(0, dot) + "-" + DateTime.Now.Millisecond.ToString() + filename.Substring(dot, filename.Length - dot);
file.SaveAs(uploadPath + filename);
StringBuilder ImagePath = new StringBuilder();
ImagePath.Append(HttpContext.Current.Server.MapPath("~"));
ImagePath.Append(@"upload\houseImage\");
ImagePath.Append(DateTime.Now.Date.ToString("yyyyMMdd"));
string strImagePath = ImagePath.ToString();
if (HouseType == 1)
{
string x80Path = ImagePath.ToString() + "\\100x75\\";
if (!Directory.Exists(x80Path))
{
Directory.CreateDirectory(x80Path);
}
photoHelper.MakeThumbnail(uploadPath + filename, x80Path.ToString() + filename, 100, 75, "Cut");
}
string waterPath= ImagePath.ToString() + "\\water\\";
if (!Directory.Exists(waterPath))
{
Directory.CreateDirectory(waterPath);
}
photoHelper.AddWaterPic(uploadPath + filename, waterPath.ToString() + filename, HttpContext.Current.Server.MapPath("~") + @"upload\logo_water.png");
//下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
bllImage.addXsHxImage(HouseID, @"~\upload\houseImage\"+DateTime.Now.Date.ToString("yyyyMMdd")+@"\[type]\" + filename, HouseType);
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
以下是可选项的参数说明:(红色的属性代表常用的)
1 |
uploader |
上传控件的主体文件,flash控件 |
2 |
script |
相对路径的后端脚本,它将处理您上传的文件。 绝对路径前缀或'/'或'http'的路径 |
3 |
checkScript |
检查该文件是否已经选择驻留在服务器上。 |
4 |
scriptData |
可提供URL传递参数。用来传递get参数。例如: 'script': 'index.jsp', 'scriptData':{'id':1,'action':'uploadify'}, 注:要设置‘method’:‘GET’. |
5 |
fileDataName |
|
6 |
method |
|
7 |
|
|
8 |
folder |
您想将文件保存到的路径。考虑到安全问题,一般并不在客户端设定后供服务器得到所存的路径。我试了下。这个参数好像以get的方式传递的。设定post得不到这个值。 |
9 |
queueID |
|
10 |
queueSizeLimit |
限制在一次队列中的次数(可选定几个文件)。默认值= 999,而一次可传几个文件有 simUploadLimit属性决定。 |
11 |
multi |
是否允许同时上传多文件,可设定true或false。 |
12 |
auto |
选定文件后是否自动上传,可设定true或false。 |
13 |
fileDesc |
出现在上传对话框中的文件类型描述。与fileExt需同时使用 |
14 |
fileExt |
支持的格式,启用本项时需同时声明fileDesc。 如:‘*.rar,*.doc |
15 |
sizeLimit |
控制上传文件的大小,单位byte |
16 |
simUploadLimit |
多文件上传时,同时上传文件数目限制。默认1 |
17 |
buttonText |
默认按钮的名字。默认BROWER |
18 |
|
使用图片按钮,设定图片的路径即可。 |
19 |
hideButton |
上传按钮的隐藏。true 或false。默认flase |
20 |
rollover |
|
21 |
width |
|
22 |
height |
|
23 |
wmode |
|
24 |
cancelImg |
|
25 |
onInit |
函数, 初始化时的状态。 onInit: function() { $("#id").html("上传前");}, |
26 |
onComplete |
event: 事件对象 queueID: 完成文件的唯一标识符。 fileObj: response: 服务器回调的数据 data: 如: onComplete: function(event, queueID, fileObj) { |
27 |
onSelectOnce |
函数:可传递二个参数 event: The event object. data: An object containing details about the select operation. |
28 |
onCancel |
函数:可传递四个参数 event: The event object. queueID: The unique identifier of the file that was cancelled. fileObj: An object containing details about the file that was selected. data: Details about the file queue. |
29 |
onClearQueue |
函数:可传递一个参数 event: The event object. |
30 |
onQueueFull |
函数:可传递二个参数 • event - The event object. • queueSizeLimit - The maximum size of the queue. |
31 |
onError |
event: The event object. queueID: The unique identifier of the file that was errored. fileObj: An object containing details about the file that was selected. errorObj: An object containing details about the error returned. |
32 |
onOpen |
函数:可传递三个参数 event: The event object. queueID: The unique identifier of the file that was opened. fileObj: An object containing details about the file that was selected. |
33 |
onProgress |
函数:可传递四个参数 event: The event object. queueID: The unique identifier of the file that was updated. fileObj: An object containing details about the file that was selected. data: An object containing details about the upload and queue. |
34 |
onSelect |
event: The event object. queueID: The unique identifier of the file that was selected. fileObj: An object containing details about the file that was selected. |
35 |
onAllComplete |
event: The event object. data: An object containing details about the upload process. |
36 |
onCheck |
函数:可传递五个参数 event: The event object. checkScript: The path to the file checking script. fileQueue: A file queue object consisting of folder: The path to the upload folder. single: True if only one file is being uploaded from the queue. |