(转)html中使用表单和input file上传图片
本文转载自:http://hi.baidu.com/love_1210/item/120e452b42b2a854c38d59eb
客户端代码:
<form name="form1" method="post" enctype="multipart/form- data" action="requestfile/asprece.aspx">//如果file框没有加runat="server",则 form里一定要加上 enctype="multipart/form-data"这样才可以实现上传文件到服务器;使用了server和没有使用
runat="server"是有区别的.使用了runat="server"的form编译后,action必定是指向本身的网页。而没
有加runat="server"的form可以指向一个网页。
<input type="file" name="file1" style="width:160px;" />
<input type="submit" name="Submit" value="添加" />
</form>
服务器端代码:
private string retvalue = "ok";
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
HttpPostedFile req = Request.Files["file1"];
if (req == null || req.ContentLength < 0)
{
Response.Write("没有文件");
Response.End();
}
else
{
try
{
string extion = System.IO.Path.GetExtension(req.FileName.ToString());
string date = DateTime.Now.ToString("yyyyMMddhhmmss").ToString();
string src = date + extion;
string pathnew = Server.MapPath("~/testfile/");
req.SaveAs(pathnew+src); //自带的方式保存文件
/*读取文件流保存
Stream stream = req.InputStream;
//string src = "test.xls";
string fullpathnew = pathnew + src;
if (!Directory.Exists(pathnew))
{
Directory.CreateDirectory(pathnew);
}
BinaryReader br = new BinaryReader(stream);
byte[] fileByte = br.ReadBytes((int)stream.Length);
// string content = fileByte.ToString();
using (FileStream fileStream = new FileStream(fullpathnew, FileMode.Create))
{
fileStream.Write(fileByte, 0, fileByte.Length);
}*/
}
catch (Exception es)
{
retvalue = es.Message.ToString();
}
finally
{
Response.Write(retvalue);
}
}
}
(转)html中使用表单和input file上传图片的更多相关文章
- ajax form表单提交 input file中的文件
ajax form表单提交 input file中的文件 现今的主流浏览器由于ajax提交form表单无法把文件类型数据提交到后台,供后台处理,可是开发中由于某些原因又不得不用ajax提交文件, 为了 ...
- Django中使用表单
使用表单 表单用 user 提交数据,是网站中比较重要的一个内容 GET 和 POST 方法 GET 和 POST 的区别 URL,全称是"统一资源定位符".用于对应互联网上的每一 ...
- input file 在开发中遇到的问题 类似ajax form表单提交 input file中的文件
最近在做项目的过程中遇到个问题,在这里做个记录防止日后忘记 现今的主流浏览器由于ajax提交form表单无法把文件类型数据提交到后台,供后台处理,可是开发中由于某些原因又不得不用ajax提交文件, 为 ...
- ASP.NET MVC中使用表单上传文件时的注意事项
最近了好久没写ASP.NET 使用HTML的FORM来上传文件了,结果写了个文件上传发现ASP.NET MVC的Controller中老是读取不到上传的文件. MVC的View(Index.cshtm ...
- JQuery input file 上传图片
表单元素file设置隐藏,通过其他元素打开: .imgfile为input file $(".ul").click(function () {return $(".img ...
- element-ui中使用表单验证的问题
<el-form ref="ruleRules" :inline="true" :model="ruleInfo"> <e ...
- input file 上传图片问题
html代码如下: <input id="fileup" type="file" accept="image/*" capture=& ...
- html5手机 input file 上传图片 调用API
<input type="file" accept="video/*;capture=camcorder"> <input type=&quo ...
- input file上传图片预览,非插件
Input标签 <input type="file" name="pic" onchange="changepic(this)" mu ...
随机推荐
- POJ 2391 Ombrophobic Bovines(二分+拆点+最大流)
http://poj.org/problem?id=2391 题意: 给定一个无向图,点i处有Ai头牛,点i处的牛棚能容纳Bi头牛,求一个最短时间T,使得在T时间内所有的牛都能进到某一牛棚里去. 思路 ...
- ${user.home} is not working in jenkins windows system
default setting create m2 in C:\Windows\system32\config\systemprofile change it to <localReposito ...
- Codeforces Round #396 (Div. 2) A,B,C,D,E
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- SSH基本管理和配置文件的使用
服务端:linl_S IP:10.0.0.15 客户端:lin_C IP:10.0.0.16 SSHD服务 SSH协议:安全外壳协议.为Secure Shell的缩写.SSH为建立在应 ...
- 五句话搞定JavaScript作用域【转】
JavaScript的作用域一直以来是前端开发中比较难以理解的知识点,对于JavaScript的作用域主要记住几句话,走遍天下都不怕... 一.“JavaScript中无块级作用域” 在Java或C# ...
- RabbitMQ入门_03_推拉模式
我们知道,消费者有两种方式从消息中间件获取消息: 推模式:消息中间件主动将消息推送给消费者 拉模式:消费者主动从消息中间件拉取消息 推模式将消息提前推送给消费者,消费者必须设置一个缓冲区缓存这些消息. ...
- css3 属性——calc()
其实在之前学习CSS3的时候,我并没有注意到有calc()这个属性,后来在看一个大牛的代码的时候看到了这个,然后就引发了后来的一系列的查找.学习,以及这篇博客的诞生.好了,废话不多说了,来干正事. 一 ...
- 雷林鹏分享:JSP 开发环境搭建
JSP 开发环境搭建 JSP开发环境是您用来开发.测试和运行JSP程序的地方. 本节将会带您搭建JSP开发环境,具体包括以下几个步骤. 配置Java开发工具(JDK) 这一步涉及Java SDK的下载 ...
- 转载 ORACLE中实现表变量的方法
源文地址:http://blog.itpub.net/750077/viewspace-2134222/ 经常看到SQLSERVER 中用表变量类型的方式就能做到缓存一个比较大的中间结果, 然后再对这 ...
- 【转载】你真的会浮点数与整型数的"互转"吗?
看了标题,你是不是觉得这TM是哪个iOS彩笔写的入门文章.好的,那咱们先来看看几个例题,看看你有没有白白点进来! int main() { float a = -6.0; int *b = & ...