(转)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 ...
随机推荐
- ubuntu16.04解决tensorflow提示未编译使用SSE3、SSE4.1、SSE4.2、AVX、AVX2、FMA的问题【转】
本文转载自:https://blog.csdn.net/Nicholas_Wong/article/details/70215127 rticle/details/70215127 在我的机器上出现的 ...
- CentOS7.2 安装zookeeper3.4.9
Zookeeper-3.4.9 下载Zookeeper-3.4.9 在/usr/local下创建hadoop文件夹 将下载的文件迁移到该文件夹下,并解压 tar -zxvf zookeeper-3.4 ...
- postman中如何使用OAuth
https://learning.getpostman.com/docs/postman/sending_api_requests/authorization/ Authorization The a ...
- ZOJ 3541 The Last Puzzle(经典区间dp)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3541 题意:有一排开关,有个开关有两个值t和d,t是按下开关后在t秒后会自 ...
- 这是一份很详细的 Retrofit 2.0 使用教程(含实例讲解)
前言 在Andrroid开发中,网络请求十分常用 而在Android网络请求库中,Retrofit是当下最热的一个网络请求库 今天,我将献上一份非常详细Retrofit v2.0的使用教程,希望你们会 ...
- hdu3951巴什博弈变型
参考博客:http://blog.csdn.net/sun897949163/article/details/50609070 特判一下m=1的情况,然后m!=1时,无论对手取多少,我只要取的让这条链 ...
- HDU 4687 Boke and Tsukkomi 一般图匹配,带花树,思路,输出注意空行 难度:4
http://acm.hdu.edu.cn/showproblem.php?pid=4687 此题求哪些边在任何一般图极大匹配中都无用,对于任意一条边i,设i的两个端点分别为si,ti, 则任意一个极 ...
- bzoj1449&&bzoj2895
题解: S连每场比赛流量1费用0 每场比赛连参赛队流量1费用0 我们发现调整一次 由win,lose变为 win+1,lose-1的费用为 (C*(win+1)^2+D*(lose-1)^2) - ( ...
- 错误 1 类,结构或接口成员声明中的标记"="无效
using System;using System.Collections.Generic;using System.Linq;using System.Text; namespace Console ...
- 如何在IDEA启动多个Spring Boot工程实例
在我讲解的案例中,经常一个工程启动多个实例,分别占用不同的端口,有很多读者百思不得其解,在博客上留言,给我发邮件,加我微信询问.所以有必要在博客上记录下,方便读者. step 1 在IDEA上点击Ap ...