使用input=file上传

时间:2022-10-22 19:13:56

前台,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上传的更多相关文章

  1. ajax&plus;ashx 完美实现input file上传文件

    1.input file 样式不能满足需求 <input type="file" value="浏览" /> IE8效果图:    Firefox效 ...

  2. 如何用一张图片代替 &&num;39&semi;input&colon;file&&num;39&semi; 上传本地文件&quest;&quest;

    今天去面试,碰到了一道题,也许是因为紧张或者喝水喝多了,一时竟然没有转过弯来,回来之后一细想原来这么简单,哭笑不得,特此记录一下! 原题是这样的:  如何用一张图片代替 'input:file' 上传 ...

  3. HTML5&colon; input&colon;file上传类型控制

    ylbtech-HTML5: input:file上传类型控制   1. 一.input:file 属性返回顶部 一.input:file属性 属性值有以下几个比较常用: accept:表示可以选择的 ...

  4. HTML5的 input&colon;file上传类型控制&lpar;转载)

    http://www.haorooms.com/post/input_file_leixing HTML5的 input:file上传类型控制 2014年8月29日 66352次浏览 一.input: ...

  5. HTML5的 input&colon;file上传类型控制

    一.input:file属性 属性值有以下几个比较常用: accept:表示可以选择的文件MIME类型,多个MIME类型用英文逗号分开,常用的MIME类型见下表. multiple:是否可以选择多个文 ...

  6. input file上传文件扩展名限制

    方法一(不推荐使用):用jS获获取扩展名进行验证: <script type="text/javascript" charset="utf-8"> ...

  7. input file 上传文件

    面试的时候遇到一个问题,要求手写的方式上传文件. 本来觉得很简单,但是结果怎么也成功不了. 前台: <form ID="form1" action="AcceptF ...

  8. input file 上传 判断文件类型、路径是否为空

    <html> <body bgcolor="white"> <TABLE cellSpacing=0 cellPadding=0 width=&quo ...

  9. 在HTML5的 input&colon;file 上传文件类型控制 遇到的问题

    1.input:file 属性的介绍  先瞅代码吧 <form> <input type="file" name="pic" accept=& ...

随机推荐

  1. oracle定时器

    /* 每10秒钟执行一次 插入一条时间 */ -- 创建table create table tab_time( current_time timestamp ); -- 创建存储过程 create ...

  2. IT之人生感悟

    从实习到现在,一直在做程序开发,工作了也有1年了吧,日子也就这么浑浑噩噩的过去了,想想将要毕业那会,原本有想考研的打算,最后还是出于各方面考虑不了了之,相比考研族提早步入了社会,既然路是自己选的,那必 ...

  3. dede栏目调用大全

    A:侧边栏常用的当前栏目的父栏目调用(5.7) 1.在include/common.inc.php增加函数 function getTopCategoryName($cid=0) { global $ ...

  4. IOS LocationManager定位国内偏移,火星坐标&lpar;GCJ-02&rpar;解决方法

    转载自:http://blog.csdn.net/swingpyzf/article/details/16972351 纠偏也可参考:http://www.2cto.com/kf/201310/253 ...

  5. 别忘记给你博客的windows live writer配置 ping服务

    写好一篇博客,想要实现秒收.就必须要为文章添加ping服务. 这里介绍一下给wlw添加ping服务的办法. 点击工具---选项--ping服务器. 在右侧栏中加入以下地址 http://rpc.pin ...

  6. &lbrack;Linux&rsqb; - Linux下安装jdk,tar方式

    下载jdk的linux下版本,下载页面http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.ht ...

  7. const 本质

    const实际上保证的,并不是变量的值不得改动,而是变量指向的那个内存地址不得改动.对于简单类型的数据(数值.字符串.布尔值),值就保存在变量指向的那个内存地址,因此等同于常量.但对于复合类型的数据( ...

  8. MyBatis 处理sql中的 大于,小于,大于等于,小于等于

    Mybatis中的sql语句中的  “<”  和   “>”  号要用转义字符   “<”   和  ”>“ ,否则会报错! 如查找年龄大于等于指定年龄的用户信息: SELEC ...

  9. astah-professional-7&lowbar;2&lowbar;0安装

    astah-professional-7_2_0-1安装 1● 下载文件 2● 安装       replace   D:\Program\astahprofessional\inst\astah-p ...

  10. SQL-39 使用索引

    题目描述 针对salaries表emp_no字段创建索引idx_emp_no,查询emp_no为10005, 使用强制索引.CREATE TABLE `salaries` (`emp_no` int( ...