asp.net type=file在上传图片到服务器
前台
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form runat="server" id="form1" method="post" enctype="multipart/form-data">
<input name="f" type="file" />
<input name="s" type="submit" />
</form>
</body>
</html>
后台
System.Web.HttpFileCollection _file = System.Web.HttpContext.Current.Request.Files;
if (_file.Count > )
{
//文件大小
long size = _file[].ContentLength;
//文件类型
string type = _file[].ContentType;
//文件名
string name = _file[].FileName;
//文件格式
string _tp = System.IO.Path.GetExtension(name); if (_tp.ToLower() == ".jpg" || _tp.ToLower() == ".jpeg" || _tp.ToLower() == ".gif" || _tp.ToLower() == ".png" || _tp.ToLower() == ".swf")
{
//获取文件流
System.IO.Stream stream = _file[].InputStream;
//保存文件
string saveName = DateTime.Now.ToString("yyyyMMddHHmmss") + _tp;
string path = DataFactory.WFile.FileUploadPath + "/upload/area/" + saveName;
// string path = Server.MapPath("images/"+savename);自己编写
_file[].SaveAs(path);
}
}
总结:
1.form 必须有runat="server"标记,
2.form 必须有enctype="multipart/form-data"标记,
3.<input type="file" />的runat="server"标记可选
完!
asp.net type=file在上传图片到服务器的更多相关文章
- Jq_input file标签上传图片到服务器
引入jQuery库引入ajaxfileupload.js上传插件库(这也是jQuery的一个插件)以ASP.NET为例 <input type="file" id=" ...
- HTML <input type="file">上传文件——结合asp.net的一个文件上传示例
HTML的代码:(关键是要在form里设置enctype="multipart/form-data",这样才能在提交表单时,将文件以二进制流的形式传输到服务器) 一. <fo ...
- 关于PHP HTML <input type="file" name="img"/>上传图片,图片大小,宽高,后缀名。
在我们的系统中,不免要上传图片,视频等文件,在上传中,需要做的一些判断,文件大小等方面. 注意: 在php.ini 中的post_max_size,upload_max_filesize默认为2M,在 ...
- input[type="file"]上传图片并显示图片
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 上传图片 ajax input type="file" 兼容 ie chroem 火狐
上传图片,转载请注明出处!!! 兼容 ie chroem 火狐 html: <div id="uploadForm"> <input id="file& ...
- 前端实现input[type='file']上传图片预览效果
众所周知JavaScript在设计上处于安全角度考虑,是不允许读写本地文件的(原因请自行百度): 但是在实际项目应用中,经常会使用到上传图片,并且可以让用户直接预览图片.对于此种做法有两种方法可以实现 ...
- vue <input type="file">上传图片、预览、删除
使用原生<input type="file">上传图片.预览.删除:multiple实现可上传多张 参数名 类型 说明 fileTypes Array 文件类型, 默认 ...
- type=file 上传图片限制 类型和尺寸 方法
<form> <input type="file" name="pic" id="pic" accept="im ...
- 一、H5(移动端)前端使用input type=file 上传图片,调用相机和相册
一.H5(移动端)前端使用input type=file 上传图片,调用相机和相册
随机推荐
- vs2015企业版和专业版秘钥
专业版:HMGNV-WCYXV-X7G9W-YCX63-B98R2企业版:HM6NR-QXX7C-DFW2Y-8B82K-WTYJV 来自http://www.cnblogs.com/xuhongfe ...
- ruby -检查数据类型
HashObj={","language"=>"zh","make"=>"Apple"," ...
- css设置背景图片
background:pink;图片在背景图上面 background-image:url(food.jpg);一张图片铺满一行background-repeat:repeat-x;同一张图片多张铺满 ...
- "mkimage" command not found - U-Boot images will not be built
编译内核的时候出现错误:"mkimage" command not found - U-Boot images will not be built 参考链接 http://blog ...
- 分析App应用市场, App应用有哪些类型
随着移动互联网的流行,APP应用也是异常火爆,App应用市场就如破冰的泉水在我们的生活中到处渗透,对于App开发的的状况来分析,企业在寻找技术人员开发一款专业的App软件的时候,必须先了解用户的需求与 ...
- openSUSE4.1 安装docker
安装完Leap后,通过YaST-Software Management安装docker. 安装 docker . yast2-docker. ruby2.1-rubygem-docker-api . ...
- simple mail example for smtp debug
vim /etc/mail.rc head /etc/rc.local | mail -s "test_email" pyz_sub1@mailtest.com
- smb服务器命令
win +r win7下运行 //linux主机地址 sudo smbpasswd -a 用户名 添加用户和密码
- Dll的生成,转化为OMF格式的DLL
extern "C" { __declspec(dllexport) int psq_add(int a, int b); } C:\Users\pansq>mkexp my ...
- (转)如何将本地git仓库上传到GitHub中托管+实践心得
Git——新手入门与上传项目到远程仓库GitHub(转) - Chen_s - 博客园http://www.cnblogs.com/Chenshuai7/p/5486278.html 注意的问题: 1 ...