前台,form的target指向iframe

  1. <form action="/EmailHandler.ashx?action=upload" id="form1" name="form1" enctype="multipart/form-data" method="post" target="hidden_frame">
  2. <div class="up_file" id="up_file">
  3. <input type="file" class="fl h_20 w_300" id="file" multiple=multiple name="upload" onchange="fileSelected()" />
  4. <input type="submit" value="上传" />
  5. </div>
  6. <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>
  7. <div id="fileInfo"></div>
  8. </form>
  1. //上传后的回调方法
  2. function callback(msg) {
  3. document.getElementById("file").outerHTML = document.getElementById("file").outerHTML;
  4. $('#attr_url').val(msg);
  5. document.getElementById('fileInfo').innerHTML +="<p>上传成功</p>"
  6. }

后台:

  1. case "upload":
  2. #region 上传文件
  3. {
  4. string path = "";
  5. if (context.Request.Files.Count > )
  6. {
  7. HttpFileCollection files = context.Request.Files;//接受文件
  8. if (files.Count > )
  9. {
  10. foreach (string i in files)
  11. {
  12. HttpPostedFile file = files[i];
  13. string fileName = Path.GetFileName(file.FileName);//获取文件名
  14. string fileExt = Path.GetExtension(fileName);//获取文件类型
  15. if (!Directory.Exists(context.Server.MapPath("/emailFiles/")))
  16. {
  17. Directory.CreateDirectory(context.Server.MapPath("/emailFiles/"));
  18. }
  19.  
  20. string dircStr = "/emailFiles/" + emp.uid + "/";
  21. if (!Directory.Exists(context.Server.MapPath(dircStr)))
  22. {
  23. Directory.CreateDirectory(Path.GetDirectoryName(context.Server.MapPath(dircStr)));
  24. }
  25. string name =dircStr+ DateTime.Now.Year+"-"+DateTime.Now.Month+"/";
  26. if (!Directory.Exists(context.Server.MapPath(name)))
  27. {
  28. Directory.CreateDirectory(Path.GetDirectoryName(context.Server.MapPath(name)));
  29. }
  30. string fileLoadName = name +DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+ fileExt;
  31. file.SaveAs(context.Server.MapPath(fileLoadName));
  32. path += fileLoadName + ',';
  33. }
  34. }
  35. path = path.TrimEnd(',');
  36. context.Response.Write("<script>parent.callback('" + path + "')</script>");//调用前台的回调方法
  37. }
  38. break;
  39. }
  40. #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开发网络篇—网络编程基础 一.为什么要学习网络编程 1.简单说明 在移动互联网时代,移动应用的特征有: (1)几乎所有应用都需要用到网络,比如QQ.微博.网易新闻.优酷.百度地图 (2)只有通过 ...

  2. JavaWeb Chapter 7 监听器

    1.  监听器Session.request.context对象属性的变化: 2.  三个对象都有生命周期和属性改变的监听: 3.  Session另外还有会话迁移和对象绑定的监听: 4.  Sess ...

  3. IIS调试技巧

    VS2010如何调试IIS上的网站 通常,我们在Visual Studio里调试ASP.NET网站,都是加个断点,然后按F5,在VS自带的虚拟服务器下调试的.但有时候,VS自带的服务器弱爆了,无法满足 ...

  4. web前端基础篇⑧

    1.伪类选择器 都以冒号开始.:focus 焦点的地方加样式:first-child 向元素的第一个子元素添加样式锚伪类:a:link {color:red} 未访问的链接 a:visited {co ...

  5. 在你决定从事iOS开发前需要清楚的几个问题

    作者:David McGraw  翻译:丁丁(jackiehoo) 原文:http://www.xmcgraw.com/what-you-need-to-know-to-start-learning- ...

  6. JVM-并发-线程安全与锁优化

    线程安全与锁优化 1.线程安全 (1)当多个线程访问一个对象时,如果不考虑这些线程在执行时环境下的调度和交替执行,也不需要进行额外的同步,或者在调用方进行任何其他的协调操作,调用这个对象的行为都可以获 ...

  7. 获取su后执行的脚本的返回值

    错误的方式: # su - testuser -c "/tmp/test.sh; echo $?"Sun Microsystems Inc.   SunOS 5.10      G ...

  8. android技巧(一):如何方便知晓当前Activity?如何管理应用中的Activity?如何最佳的启动一个Activity?

    1.如何方便知晓当前Activity? 可以不看代码根据当前界面就知道界面所在Activity的写法: 建立BaseActivity,继承自Activity,在BaseActivity的OnCreat ...

  9. 【winform 学习】登录

    一直都是做asp.net,没有做过winform项目,新建个项目后,就啥不会了,不知道从何下手. 简单的登录项目也不会,画了个登录界面后,就遇到了,跳入主界面后,怎样将登录界面关闭的问题. 在网上找到 ...

  10. HTMl5-canvas 入门级复习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...