引自 文章 http://www.cnblogs.com/babycool/archive/2012/08/04/2623137.html
将文章里的代码整合在了一个解决方案里,直接可以下载测试,上代码先
前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <link href="js/uploadify/uploadify.css" rel="stylesheet" type="text/css" /> <script src="js/uploadify/jquery-1.4.1-vsdoc.js" type="text/javascript"></script> <script src="js/uploadify/jquery.uploadify-3.1.js" type="text/javascript"></script> <script src="js/uploadify/uploadHandle2_ashx.js" type="text/javascript"></script> </head> <body> <div> <%--用来作为文件队列区域--%> <div id="fileQueue"> </div> <input type="file" name="uploadify" id="uploadify" /> <div> <a href="javascript:$('#uploadify').uploadify('upload')">上传</a>| <a href="javascript:$('#uploadify').uploadify('cancel')">取消上传</a> </div> </div> </body> </html>
后台ashx文件
<%@ WebHandler Language="C#" Class="imageHandler" %> using System; using System.Web; using System.IO; public class imageHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //接收上传后的文件 HttpPostedFile file = context.Request.Files["Filedata"]; //其他参数 //string somekey = context.Request["someKey"]; //string other = context.Request["someOtherKey"]; //获取文件的保存路径 string uploadPath = HttpContext.Current.Server.MapPath("UploadImages" + "\"); //判断上传的文件是否为空 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; } } }
示例解决方案下载 ajax无刷新上传图片_2013_12_19_14_17.rar