前台,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. iOS开发网络篇—文件的上传

    iOS开发网络篇—文件的上传 说明:文件上传使用的时POST请求,通常把要上传的数据保存在请求体中.本文介绍如何不借助第三方框架实现iOS开发中得文件上传. 由于过程较为复杂,因此本文只贴出部分关键代 ...

  2. Java类的成员函数调用顺序

    class A { public A() { System.out.println("----------A 构造-------------"); } static void sb ...

  3. IE下只读INPUT键入BACKSPACE 后退问题(readonly='true')

    在IE下,如果在readonly的input里面键入backspace键,会触发history.back(), 用以下jquery代码修正之 $("input[readOnly]" ...

  4. 保留json字符串中文的函数,代替json_encode

    // 格式化json中的汉字函数    protected function encode_json($str) {        $strs = urldecode(json_encode($thi ...

  5. Python的平凡之路(2)

    一.标准库(sys & os):   Python 的标准库(standard library) 是随着 Python 一起安装在你的电脑中的,是 Python 的一部分 (当然也有特殊情况. ...

  6. 另一种图片上传 jquery.fileupload.js

    今天遇到另外一种上传图片方法 用jquery.fileupload.js <input type="file" name="file[]" multipl ...

  7. Hubilder快捷键

    /* tips.txt的内容可以在HBuilder启动封面中显示.你可以自定义一个有趣的启动tips,增加[user]开头的文本内容即可.比如[user]我要减肥!  */ 你按照Hello HBui ...

  8. linux系统io的copy

    #include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h&g ...

  9. POJ 3176 简单DP

    Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16448 Accepted: 10957 Descrip ...

  10. ASP代码审计 -4.命令执行漏洞总结

    命令执行漏洞: 保存为cmd.asp,提交链接: http://localhost/cmd.asp?ip=127.0.0.1 即可执行命令 <%ip=request("ip" ...