(转)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 ...
随机推荐
- php 二维数组
<?php // 一个二维数组 $cars=array ( array(,), array(,), array(,) ); ?>
- package 'orocos-bfl' not found
-- ==> add_subdirectory(bp_fusion) -- checking for module 'orocos-bfl' -- package 'orocos-bfl' no ...
- install ros-indigo-pcl-ros
CMake Warning at /opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake: (find_package): Could not fi ...
- python 十进制数转二进制数
def convertToBinary(n): """Function to print binary number for the input decimal usin ...
- UI 交互
动效设计 亮色优缺点 排版 原型图交互说明
- Android反射机制:手把手教你实现反射
什么是反射机制? JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称 ...
- Flutter基础Widget之按钮(RaisedButton、FlatButton、OutlineButton,IconButton)
Flutter中给我们预先定义好了一些按钮控件给我们用,常用的按钮如下 RaisedButton :凸起的按钮,其实就是Android中的Material Design风格的Button ,继承自Ma ...
- Android之修改用户头像并上传服务器(实现手机拍照和SD卡选择上传)
写了这么多个的APP,最近才把他这个功能写上来,就抽取其中的用户修改头像的相关操作这个功能写了这篇博客,来与大家分享,希望对你有所帮助. 案例包含了: Xutil图片上传 拍照和SD卡选择图片 图片缓 ...
- Rancher快速入门
https://www.cnrancher.com/docs/rancher/v2.x/cn/overview/quick-start-guide/
- kmp算法中的next数组实例解释
假设求串′ababaaababaa′的next数组 模式串 a b a b a a a b a b a a 下标 1 2 3 4 5 6 7 8 9 10 11 12 1.前两位:next数组前两位一 ...