前台,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+ashx 完美实现input file上传文件

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

  2. 如何用一张图片代替 'input:file' 上传本地文件??

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

  3. HTML5: input:file上传类型控制

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

  4. HTML5的 input:file上传类型控制(转载)

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

  5. HTML5的 input: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:file 上传文件类型控制 遇到的问题

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

随机推荐

  1. 二模 (13)day2

    第一题: 题目大意: 给出一个N*M的矩阵,定义一条路径的权值为经过的所有点权值的最大值.求一条从第一行到第N行的路径,使得路径权值最小. N,M<=1000 矩阵内点的权值小于1000. 解题 ...

  2. 在Eclipse上建立hadoop2.2.0/hadoop2.4.0源代码阅读环境

    1.安装依赖的包: yum install gcc-c++ g++ autoconf automake libtool cmake zlib1g-dev pkg-config libssl-dev 2 ...

  3. UITableViewCell左对齐的方法

    if ([TabelView respondsToSelector:@selector(setLayoutMargins:)]) {        [TabelView setLayoutMargin ...

  4. Android之View和SurfaceView

    Android之View和SurfaceView Android游戏当中主要的除了控制类外就是显示类View.SurfaceView是从View基类中派生出来的显示类.android游戏开发中常用的三 ...

  5. SharePoint开发——利用CSOM逐级获取O365中SharePoint网站的List内容

    博客地址:http://blog.csdn.net/FoxDave 本文介绍如何利用SharePoint客户端对象模型(.NET)逐级获取Office 365网站中List的内容,仅仅是示例,没有 ...

  6. priority_queue 优先队列用法

    //采用默认优先关系: //(priority_queue<int>que;) //Queue 0: // 91 83 72 56 47 36 22 14 10 7 3 // //采用结构 ...

  7. JM8.6学习

    1. vs2010 设置参数 编译运行JM8.6 (参考http://bbs.chinavideo.org/forum.php?mod=viewthread&tid=15695&hig ...

  8. Java笔记5-修饰符,重载,递归,数组

    方法的定义修饰符 返回类型 方法名(参数列表) throws 异常类型列表 { //方法体}==如何来设计一个方法:案例:请根据如下的业务分别设计出方法1.根据给定的年份判断是否是闰年?public ...

  9. c++作用域运算符---7

    原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ ::是C++里的“作用域运算符”. 比如声明了一个类A,类A里声明了一个成员函数void f(),但没有 ...

  10. 百度翻译&&金山词霸API

    #/usr/bin/env python3 #coding=utf8 """百度翻译api功能实现函数,本模块基于Python3.x实现,getTransResult(q ...