Input控件上传文件
2012-02-26 20:12
204 查看
<%@ 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> <title></title> </head> <body> <form action="exec/Upload.ashx" enctype="multipart/form-data" method="post"> <input name="file" type="file" /> <input type="submit" value="提交" /> </form> </body> </html>
页面1里面写这些
<%@ WebHandler Language="C#" Class="Upload" %> using System; using System.Web; public class Upload : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; HttpFileCollection imgs = context.Request.Files; if (imgs.Count>0) { for (int i = 0; i < imgs.Count; i++) { if (imgs[i].ContentLength!=0) { string oldName=imgs[i].FileName.ToString(); string imgName = Guid.NewGuid().ToString(); string imgType = oldName.ToString().Substring(oldName.LastIndexOf(".")); string imgPath = "~/upload/" + imgName + imgType; imgs[i].SaveAs(context.Server.MapPath(imgPath)); } } } } public bool IsReusable { get { return false; } } }
一般处理程序代码
点击下载源代码
相关文章推荐
- Ajax Input控件上传文件
- 给上传文件的input控件“美容”
- 如何设置上传文件控件 input type="file" 的 默认值
- Web开发之input file控件限制上传文件类型
- 通过HtmlInputFile控件上传文件的类
- Input控件上传文件
- 使用html input(file)控件上传文件
- input file控件限制上传文件类型
- 在IE中必须点击input file 控件的浏览按钮才能提交上传,否则没有权限 。js文件报拒绝访问,解决办法是将input file控件定位到你要点击的地方 ,并且input file做成透明的
- input[type=file] 样式美化,input上传按钮美化,使用ajax上传无须控件上传文件
- 【翻译】Styling an input type="file"美化文件上传控件
- ASP.Net之HTMLInputFile控件上传文件
- C#多文件上传,客户端input file控件
- ***文件上传控件bootstrap-fileinput的使用和参数配置说明
- input file控件限制上传文件类型
- Input控件上传文件
- input file控件限制上传文件类型 网页上添加一个input file HTML控件: 1 <input id="File1" type="file" /> 默认是这样的,所有文件类
- 基于bootstrap的文件上传控件bootstrap fileinput
- 通过HtmlInputFile控件上传文件的类
- input file 文件上传控件隐藏后用button触发它的click事件文件传不上去的解决方案