使用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=& ...
随机推荐
- ZJOI2015 一试。
虽然早就知道会是这个结果,但是看到的成绩时候还是有些忧伤,奇迹果然还是没有发生. 想了想还是应该写篇博文 纪念一下这段经历. Day0: 报道之后直接去了宾馆,然后意外的发现冬令营时候的室友wxh就住 ...
- 一口气学会Linq
千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看完它!!! 在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之 ...
- python操作excel表格详解(xlrd/xlwt)
http://www.2cto.com/kf/201501/373655.html http://blog.csdn.net/b_h_l/article/details/17001395 利用pyth ...
- java编码转换 unicode to utf-8
private String decodeUnicode(String theString) { char aChar; int len = theString.length(); StringBuf ...
- 4、时间同步ntp服务的安装于配置(作为客户端的配置)
yum安装ntpd服务 .yum -y install ntp ntpdate (安装时间同步ntp服务) . vi /etc/ntp.conf (修改ntpd服务的配置文件) 3.修改配置文 ...
- Photo Kit 框架
http://geek.csdn.net/news/detail/56031 http://www.jianshu.com/p/9988303b2429 http://blog.sina.com.cn ...
- UE4 C++ 使用FTimeLine/FTime 实例 Actor moving faster than Timeline
https://answers.unrealengine.com/questions/313698/timeline-issues.html https://docs.unrealengine.c ...
- web.xml在Servlet3.0中的新增元素
metadata-complete: 当属性为true时,该Web应用将不会加载注解配置的Web组件(如Servlet.Filter.Listener) 当属性为false时,将加载注解配置的Web组 ...
- webApp--cordova 系列1
1.在node,npm 可用的前提下 npm install -g cordova 大约10分钟后装完,cmd中输入cordova -v 验证是否安装成功 2.cordova项目打包是用ant完成, ...
- HDU 5838 (状压DP+容斥)
Problem Mountain 题目大意 给定一张n*m的地图,由 . 和 X 组成.要求给每个点一个1~n*m的数字(每个点不同),使得编号为X的点小于其周围的点,编号为.的点至少大于一个其周围的 ...