使用input=file上传
前台,form的target指向iframe
- <form action="/EmailHandler.ashx?action=upload" id="form1" name="form1" enctype="multipart/form-data" method="post" target="hidden_frame">
- <div class="up_file" id="up_file">
- <input type="file" class="fl h_20 w_300" id="file" multiple=multiple name="upload" onchange="fileSelected()" />
- <input type="submit" value="上传" />
- </div>
- <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>
- <div id="fileInfo"></div>
- </form>
- //上传后的回调方法
- function callback(msg) {
- document.getElementById("file").outerHTML = document.getElementById("file").outerHTML;
- $('#attr_url').val(msg);
- document.getElementById('fileInfo').innerHTML +="<p>上传成功</p>"
- }
后台:
- case "upload":
- #region 上传文件
- {
- string path = "";
- if (context.Request.Files.Count > )
- {
- HttpFileCollection files = context.Request.Files;//接受文件
- if (files.Count > )
- {
- foreach (string i in files)
- {
- HttpPostedFile file = files[i];
- string fileName = Path.GetFileName(file.FileName);//获取文件名
- string fileExt = Path.GetExtension(fileName);//获取文件类型
- if (!Directory.Exists(context.Server.MapPath("/emailFiles/")))
- {
- Directory.CreateDirectory(context.Server.MapPath("/emailFiles/"));
- }
- string dircStr = "/emailFiles/" + emp.uid + "/";
- if (!Directory.Exists(context.Server.MapPath(dircStr)))
- {
- Directory.CreateDirectory(Path.GetDirectoryName(context.Server.MapPath(dircStr)));
- }
- string name =dircStr+ DateTime.Now.Year+"-"+DateTime.Now.Month+"/";
- if (!Directory.Exists(context.Server.MapPath(name)))
- {
- Directory.CreateDirectory(Path.GetDirectoryName(context.Server.MapPath(name)));
- }
- string fileLoadName = name +DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+ fileExt;
- file.SaveAs(context.Server.MapPath(fileLoadName));
- path += fileLoadName + ',';
- }
- }
- path = path.TrimEnd(',');
- context.Response.Write("<script>parent.callback('" + path + "')</script>");//调用前台的回调方法
- }
- break;
- }
- #endregion
使用input=file上传的更多相关文章
- ajax+ashx 完美实现input file上传文件
1.input file 样式不能满足需求 <input type="file" value="浏览" /> IE8效果图: Firefox效 ...
- 如何用一张图片代替 'input:file' 上传本地文件??
今天去面试,碰到了一道题,也许是因为紧张或者喝水喝多了,一时竟然没有转过弯来,回来之后一细想原来这么简单,哭笑不得,特此记录一下! 原题是这样的: 如何用一张图片代替 'input:file' 上传 ...
- HTML5: input:file上传类型控制
ylbtech-HTML5: input:file上传类型控制 1. 一.input:file 属性返回顶部 一.input:file属性 属性值有以下几个比较常用: accept:表示可以选择的 ...
- HTML5的 input:file上传类型控制(转载)
http://www.haorooms.com/post/input_file_leixing HTML5的 input:file上传类型控制 2014年8月29日 66352次浏览 一.input: ...
- HTML5的 input:file上传类型控制
一.input:file属性 属性值有以下几个比较常用: accept:表示可以选择的文件MIME类型,多个MIME类型用英文逗号分开,常用的MIME类型见下表. multiple:是否可以选择多个文 ...
- input file上传文件扩展名限制
方法一(不推荐使用):用jS获获取扩展名进行验证: <script type="text/javascript" charset="utf-8"> ...
- input file 上传文件
面试的时候遇到一个问题,要求手写的方式上传文件. 本来觉得很简单,但是结果怎么也成功不了. 前台: <form ID="form1" action="AcceptF ...
- input file 上传 判断文件类型、路径是否为空
<html> <body bgcolor="white"> <TABLE cellSpacing=0 cellPadding=0 width=&quo ...
- 在HTML5的 input:file 上传文件类型控制 遇到的问题
1.input:file 属性的介绍 先瞅代码吧 <form> <input type="file" name="pic" accept=& ...
随机推荐
- iOS开发网络篇—网络编程基础
iOS开发网络篇—网络编程基础 一.为什么要学习网络编程 1.简单说明 在移动互联网时代,移动应用的特征有: (1)几乎所有应用都需要用到网络,比如QQ.微博.网易新闻.优酷.百度地图 (2)只有通过 ...
- JavaWeb Chapter 7 监听器
1. 监听器Session.request.context对象属性的变化: 2. 三个对象都有生命周期和属性改变的监听: 3. Session另外还有会话迁移和对象绑定的监听: 4. Sess ...
- IIS调试技巧
VS2010如何调试IIS上的网站 通常,我们在Visual Studio里调试ASP.NET网站,都是加个断点,然后按F5,在VS自带的虚拟服务器下调试的.但有时候,VS自带的服务器弱爆了,无法满足 ...
- web前端基础篇⑧
1.伪类选择器 都以冒号开始.:focus 焦点的地方加样式:first-child 向元素的第一个子元素添加样式锚伪类:a:link {color:red} 未访问的链接 a:visited {co ...
- 在你决定从事iOS开发前需要清楚的几个问题
作者:David McGraw 翻译:丁丁(jackiehoo) 原文:http://www.xmcgraw.com/what-you-need-to-know-to-start-learning- ...
- JVM-并发-线程安全与锁优化
线程安全与锁优化 1.线程安全 (1)当多个线程访问一个对象时,如果不考虑这些线程在执行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方进行任何其他的协调操作,调用这个对象的行为都可以获 ...
- 获取su后执行的脚本的返回值
错误的方式: # su - testuser -c "/tmp/test.sh; echo $?"Sun Microsystems Inc. SunOS 5.10 G ...
- android技巧(一):如何方便知晓当前Activity?如何管理应用中的Activity?如何最佳的启动一个Activity?
1.如何方便知晓当前Activity? 可以不看代码根据当前界面就知道界面所在Activity的写法: 建立BaseActivity,继承自Activity,在BaseActivity的OnCreat ...
- 【winform 学习】登录
一直都是做asp.net,没有做过winform项目,新建个项目后,就啥不会了,不知道从何下手. 简单的登录项目也不会,画了个登录界面后,就遇到了,跳入主界面后,怎样将登录界面关闭的问题. 在网上找到 ...
- HTMl5-canvas 入门级复习
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...