读书人

uploadify上传文件控件后台怎么获取它

发布时间: 2013-07-11 15:38:46 作者: rapoo

uploadify上传文件控件后台如何获取它的文件大小和名字


控件
[解决办法]
uploadify提供了js的函数可以调用获取,如果是已经上传,在后台接收文件的处理类里一样可以得到
[解决办法]
比如你上传页面是

$("#uploadify").uploadify({
'uploader': 'Js/jquery.uploadify-v2.1.4/uploadify.swf',
'script': 'UploadHandler.ashx',//引用Handler
'buttonImg':'Js/jquery.uploadify-v2.1.4/select.gif',//选择文件按钮
'cancelImg': 'Js/jquery.uploadify-v2.1.4/cancel.gif',//取消上传按钮
'width': 150,//按钮宽度
'height': 54,//按钮高度
'wmode': 'transparent',//使浏览按钮的flash背景文件透明

其中'script': 'UploadHandler.ashx',//引用Handler
UploadHandler.ashx文件中即可用来处理上传的一些操作
如:
<%@ WebHandler Language="C#" Class="UploadHandler" %>

using System;
using System.Web;
using System.IO;

public class UploadHandler : IHttpHandler {

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8";


HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath = HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\";



if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);

//上传成功后让上传队列的显示自动消失
context.Response.Write("1");
}
else
{
context.Response.Write("0");
}
}

public bool IsReusable {
get {
return false;
}
}

}



比如其中几个:
FileInfo fi = new FileInfo(file.FileName);

int fileLength = file.ContentLength;
string oldfilename = fi.Name;
string scExtension = fi.Extension.ToLower();

[解决办法]
uploadify这个控件不错的 不过要注意版本啊 楼主用的什么版本? 2楼的例子是2.*的版本 跟3.*的版本差别还是比较的大地!
[解决办法]
引用:
Quote: 引用:

uploadify这个控件不错的 不过要注意版本啊 楼主用的什么版本? 2楼的例子是2.*的版本 跟3.*的版本差别还是比较的大地!


uploadify-v2.1.4版本的,我就是想在后台获取文件大小和名称之后方便插入数据库中!


你看下2楼的例子 这句是关键:HttpPostedFile file = context.Request.Files["Filedata"];
下面的file.Name可以获取文件名称。
另file.ContentLength可以获取文件大小

读书人网 >asp.net

热点推荐