使用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=& ...
随机推荐
- 不用static,巧用对象.方法调用java中的函数
先生成一个对象,用"对象.方法()"的方式调用. java中的main方法是静态的,用于程序的入口,在静态方法中无法调用非静态方法,只能调用静态方法.想调用静态方法的话就要先生成该 ...
- HDU 1171 背包
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- swiper 内容超出纵向滚动 解决办法
.swiper-slide { overflow: auto; } var swiper = new Swiper('.swiper-container', { direction: 'verti ...
- CSS简单布局总结
display block 块级元素,占据一行 none 隐藏 inline 允许同一行显示,但不再有宽和高 inline-block 允许在一行的块级元素,可 ...
- div嵌套引起的margin-top不起作用
通常大家在制作网页的过程中会遇到很多棘手的问题,比如我在写一个页面的时候,遇到了div嵌套引起的margin-top不起作用,对内部的div设置margin-top时,内部对于外部的div并没有产生一 ...
- PKU 1002解题总结
闲来无事,研究了一下PKU1002的题目,大意就是把含有字母的电话号码,转换为数字,然后再计算每个电话号码出现的次数,输出.本来蛮简单的一道题,结果折腾了好久,主要也是自己的水平太菜了,先是直接用字符 ...
- PAT (Basic Level) Practise:1016. 部分A+B
[题目链接] 正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA.例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6. 现给定A.DA. ...
- 防刷新jq左侧滚动条导航展示
html代码: <div class="fangchan_navcont"> <div class="fangchan_nav" ...
- tableView
Table View简单描述: 在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View ...
- 多媒体音频(audio)
随着计算机技术的发展,特别是海量存储设备和大容量内存在PC机上的实现,对音频媒体进行数字化处理便成为可能.数字化处理的核心是对音频信息的采样,通过对采集到的样本进行加工,达成各种效果,这是音频媒体数字 ...