方便引用写成了一个用户控件.
前台代码
清除
' == 'True') {
$("#").hide();
$("#").show();
}
else {
$("#").show();
$("#").hide();
}
$("#").uploadify({
swf: 'http://static.kecq.com/js/uploadify3.2/uploadify.swf',
uploader: 'http://static.kecq.com/Upload.axd?uploadDir=&objectID=&isImage=', //后台处理
cancelImage: 'http://static.kecq.com/js/uploadify3.2/uploadify-cancel.png', //单个取消按钮
buttonImage: 'http://static.kecq.com/js/uploadify3.2/upload.gif',
//buttonClass:'',
fileObjName: '', //文件对象名 缺省'Filedata'
//progressData:'speed', //或 'percentage','all'
queueID: '', //文件队列
auto: true, //true:选择文件后自动开始上传;false:手动触发
multi: false, //多文件上传,
// uploadLimit: '4', //一次上传的文件的个数
//formData:{'userName':'userName','userPassword':'userPassword'},
fileTypeExts: '', //.jpg,.bmp,.gif,.png,.doc,.pdf,.rar,.zip,.7z,可上传文件
fileTypeDesc: '', //显示的文件类型
buttonText: 'upload',
width: '60',
height: '30',
removeCompleted: true, //上传成功后的文件,是否在队列中自动删除
fileSizeLimit: '60000KB', //大小限制
onUploadError: function (file, errorCode, errorMsg, errorString) { //当单个文件上传出错时触发
alert('文件:' + file.name + ' 上传失败: ' + errorString);
}, //返回错误信息
onSelect: function (file) {
jBox.tip('正在上传 ...', 'loading');
},
onUploadSuccess: function (file, data, response) { //上传完成时触发(每个文件触发一次)
// $("#").html("上传完成");
var ss = eval(data);
if (response) {
$("#").val(ss.fileUrl);
$("#").attr("src", ss.fileUrl);
$('#').val(response.thumUrl);
}
else {
$("#").append("" + ss.error + "");
}
},
onUploadProgress: function (file, bytesUploaded, bytesTotal, totalBytesUploaded) {
},
onQueueComplete: function (queueData) {
//jBox.tip('成功上传' + queueData.uploadsSuccessful + "个文件", 'success');
jBox.tip('上传完成', 'success');
}
});
$("#").click(function () {
$("#").val("");
$("#").attr("src", "http://static.kecq.com/images/common/nopic.jpg");
$('#').val("");
});
});" _ue_custom_node_="true">后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Include_ASCX_UploadFile : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
//允许上传的扩展名
internal string ext = "*.doc;*.pdf;*.rar;*.zip;*.7z;*.chm;*.jpg;*.gif;*.png;*.bak";
//是否图片
private bool isImage = false;
private int thumWidth = 0; //缩放图片宽 如果thumWidth thumheight 有一个为0 则不缩放
private int thumHeight = 0; //缩放图片高 如果thumWidth thumheight 有一个为0 则不缩放
private int thumPassSizeKB = 0; //图片大小超过多少KB 则使用缩放 如果为0 则始终缩放
#region 属性
////// 获取或设置文件或图片路径
///public string FileUrl
{
get
{
return fileUrl.Text.Trim();
}
set
{
fileUrl.Text = value;
if (!String.IsNullOrEmpty(value))
{
this.showImage.ImageUrl = value;
}
else
{
this.showImage.ImageUrl = "http://static.kecq.com/images/common/nopic.jpg";
}
}
}
////// 获取或设置上传的相对目录
///public string UploadDir
{
set;
get;
}
////// 获取或设置关联对象ID
///public string ObjectID
{
get;
set;
}
////// 获取或设置是否图片
///public bool IsImage
{
set
{
if (value == true)
{
ext = "*.png;*.jpg;*.gif;*.bmp;";
}
isImage = value;
}
get
{
return isImage;
}
}
////// 获取缩略图地址
///public string ThumUrl
{
get
{
return thumUrl.Value;
}
}
////// 缩放图片宽 如果thumWidth thumheight 有一个为0 则不缩放
///public int ThumWidth
{
set { thumWidth = value; }
get { return thumWidth; }
}
////// 缩放图片高 如果thumWidth thumheight 有一个为0 则不缩放
///public int ThumHeight
{
set { thumHeight = value; }
get { return thumHeight; }
}
////// 图片大小超过多少KB 则使用缩放 如果为0 则始终缩放
///public int ThumPassSizeKB
{
set { thumPassSizeKB = value; }
get { return thumPassSizeKB; }
}
#endregion
}
珂珂的个人博客 - 一个程序猿的个人网站