日期:2014-05-17  浏览次数:20413 次

uploadify上传文件控件后台如何获取它的文件大小和名字
本帖最后由 xuhongfei111 于 2013-05-04 16:29:44 编辑
如题,利用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"]) + "\\";