jquery上传文件

jquery上传文件,是用的jquery的插件来进行文件的上传。

jquery上传文件的插件的名称是:jquery.uploadify.js,可以去网上进行下载:http://www.uploadify.com/download/

新建一个default.html页面,html代码如下:

<html>
<head>
<title>Upload File Page</title>
<script type="text/javascript" src="JS/jquery-1.4.2.js"></script>
<script type="text/javascript" src="JS/jquery.uploadify.js"></script>         //插件的导入
<link rel="stylesheet" href="CSS/uploadify.css" type="text/css" media="screen" />
</head>
<body>
<input type="file" name="fileInput" id="fileInput" />
<br />
  <a href="javascript:$('#fileInput').fileUploadStart();">Upload Files</a> | <a href="javascript:$('#fileInput').fileUploadClearQueue();">Clear Queue</a>
<script type="text/javascript">
    $(document).ready(function() {
        $('#fileInput').fileUpload({
            'uploader': 'Flash/uploader.swf',       //上传文件的进度条
            'script': 'UploadFileForm.aspx',         //上传文件的后台处理页面
            'cancelImg': 'Images/cancel.png',     //取消上传的图片
            'auto': false,
            'multi': true,
            'simUploadLimit': 3,                   //上传文件大小的限制
            'folder': '/UploadFiles',              //上传的文件夹
            'onComplete': function(event, queueID, fileObj, response, data) {             //上传完成后的操作
                alert(response);
            }
        });
    });
</script>
</body>
</html> 

 UploadFileForm.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Response.ContentType = "text/plain";
                Response.Charset = "utf-8";
                string strUploadPath = Request.PhysicalApplicationPath + Request.QueryString["folder"].Trim('/').Replace("/", "\\") + "\\";
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFile postedFile = Request.Files[i];
                    string fileName = strUploadPath + Path.GetFileName(postedFile.FileName);
                    if (fileName != "")
                    {
                        postedFile.SaveAs(fileName);
                    }
                }
                Response.Write("Upload The File Successfully!");
            }
            catch (Exception ex)
            {
                Response.ContentType = "text/plain";
                Response.Write(ex.Message);
            }
            finally
            {
                Response.Flush();
                Response.End();
            }
        } 

更多的信息可以去官网上去看。http://www.uploadify.com/documentation/

 

posted @ 2010-09-25 10:39  chenping2008  阅读(45105)  评论(6编辑  收藏  举报