mvc上传,下载,浏览文件功能(用uploadify插件)
类
public class UpLoadFileController : Controller
{
//
// GET: /UpLoadFile/ public ActionResult Index()
{
return View();
} /// <summary>
/// 上传文件【上传文件到UploadFiles文件夹】
/// </summary>
/// <param name="fileData"></param>
/// <param name="Id"></param>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Post)]
public ContentResult UpLoadFile(HttpPostedFileBase fileData, String Id)
{
ControllerContext.HttpContext.Request.ContentEncoding = Encoding.UTF8;
ControllerContext.HttpContext.Response.ContentEncoding = Encoding.UTF8;
ControllerContext.HttpContext.Response.Charset = "UTP-8"; string filePath = Server.MapPath(@"/UploadFiles");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath);
if (fileData != null)
{
string fileSaveName = Path.Combine(filePath, fileData.FileName);
fileData.SaveAs(fileSaveName);
return Content("成功");
}
return Content("失败");
} /// <summary>
/// 获取文件【下载】
/// </summary>
/// <param name="id">文件名</param>
/// <returns></returns>
public FilePathResult GetFile(string id)
{
if (string.IsNullOrEmpty(id))
{
return null;
}
id = id.Replace("__", ".");
string path = "UploadFiles";
string filePath = Server.MapPath(@"/" + path);
string fileSaveName = Path.Combine(filePath, id);
return File(fileSaveName, "image/*", id);
} }
Index.cshtml
@{
ViewBag.Title = "上传文件";
}
<script src="~/Content/uploadify/jquery.uploadify.js?ver=@DateTime.Now.Ticks"></script>
<link href="~/Content/uploadify/uploadify.css" rel="stylesheet" />
@*上传文件*@
<div>
<input class="easyui-validatebox" type="hidden" id="Attachment_GUID" name="Attachment_GUID" />
<input id="file_upload" name="file_upload" type="file" >
@* <a href="javascript:void(0)" class="easyui-linkbutton" id="btnUpload" data-options="plain:true,iconCls:'icon-save'"
onclick="javascript: $('#file_upload').uploadify('upload', '*')">上传</a>
<a href="javascript:void(0)" class="easyui-linkbutton" id="btnCancelUpload" data-options="plain:true,iconCls:'icon-cancel'"
onclick="javascript: $('#file_upload').uploadify('cancel', '*')">取消</a>
<div id="fileQueue" class="fileQueue"></div>*@
<a href="javascript:void(0)" class="easyui-linkbutton" id="btnBrowse" >浏览</a>
<div id="div_files">
<a id="downFile" href="#">下载文件</a>
<img id="uploadImg" src=""/>
</div>
<br />
</div>
@*弹出层*@
@Html.Partial("Contact")
<script>
$(function () {
$("#btnBrowse").click(function () {
PopLayout.Pop($("#uploadImg").attr("src"));
});
$("#file_upload").uploadify({
height: 30,
width: 120,
buttonText: "选择",
multi: false,
swf: '/Content/uploadify/uploadify.swf',
uploader: '@Url.Action("UpLoadFile","UpLoadFile")',
onFallback: function () {
alert("不支持flash");
},
onUploadError: function (file, errorCode, errorMsg, errorString) {
alert("文件" + file.name + "上传失败: " + errorString);
},
onUploadSuccess: function (file, data, response) {
if (true) {
//alert(file.name);
var id = file.name.replace(".", "__");;
$("#downFile").attr("href", "/UpLoadFile/GetFile/" + id);
$("#uploadImg").attr("src", "/UploadFiles/" + file.name);
}
//alert("文件" + file.name + "上传成功:" + data);
}
});
});
</script>
@Html.Partial("Contact") 嵌入Contact.cshtml文件
请看上篇文章,弹出层:http://www.cnblogs.com/liujinwu-11/p/4334568.html
mvc上传,下载,浏览文件功能(用uploadify插件)的更多相关文章
- asp.net mvc上传头像加剪裁功能
原文:asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jqu ...
- mvc上传头像加剪裁功能
asp.net mvc上传头像加剪裁功能 正好项目用到上传+剪裁功能,发上来便于以后使用. 我不能告诉你们其实是从博客园扒的前台代码,哈哈. 前端是jquery+fineuploader+jquery ...
- SpringMVC文件上传下载(单文件、多文件)
前言 大家好,我是bigsai,今天我们学习Springmvc的文件上传下载. 文件上传和下载是互联网web应用非常重要的组成部分,它是信息交互传输的重要渠道之一.你可能经常在网页上传下载文件,你可能 ...
- Xshell5下利用sftp上传下载传输文件
sftp是Secure File Transfer Protocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp 与 ftp 有着几乎一样的语法和功能.SFTP 为 SSH ...
- Spring框架学习(8)spring mvc上传下载
内容源自:spring mvc上传下载 如下示例: 页面: web.xml: <?xml version="1.0" encoding="UTF-8"?& ...
- 使用ftp软件上传下载php文件时换行丢失bug
正 文: 在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下notepad++编辑器写好的php文件,在使用ftp上传到linux服务器后,php文件的换行符全部丢失了, ...
- 使用ftp软件上传下载php文件时换行丢失bug(全部变为一行)
文章来源:http://www.piaoyi.org/computer/ftp-php-r-n-bug.html 正 文: 在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下 ...
- java FTP 上传下载删除文件
在JAVA程序中,经常需要和FTP打交道,比如向FTP服务器上传文件.下载文件,本文简单介绍如何利用jakarta commons中的FTPClient(在commons-net包中)实现上传下载文件 ...
- ****使用ftp软件上传下载php文件时换行符丢失bug
在使用ftp软件上传下载php源文件时,我们偶尔会发现在本地windows下notepad++编辑器写好的php文件,在使用ftp上传到linux服务器后,php文件的换行符全部丢失了,导致php文件 ...
- Spring Boot2(十四):单文件上传/下载,文件批量上传
文件上传和下载在项目中经常用到,这里主要学习SpringBoot完成单个文件上传/下载,批量文件上传的场景应用.结合mysql数据库.jpa数据层操作.thymeleaf页面模板. 一.准备 添加ma ...
随机推荐
- div 居中进行总结
1.margin:auto ;让元素居中,需要确定元素的宽度,并且需要是块元素 eg: div { width:200px; height:200px; background:#222; margin ...
- 把zlog封装成模块,隐藏zlog
mylog.h #ifndef _MY_LOG_H #define _MY_LOG_H int init(char *filename); void *get_category(char * cate ...
- HTTP服务负载均衡总结
从一开始就要思考扩展的架构,所谓可扩展性指的是通过扩展规模提高承载能力的本领,往往体现在增加物理服务器或者集群节点.负载均衡是常见的水平扩展的手段. 目标:(1)减少单点故障(2)提升整体吞吐量(3) ...
- android and javascript
layout-------->HTML activity-------->JavaScript R资源管理者----------->layout, string, styles, c ...
- 这样就算会了PHP么?-4
数组初步 <?php $ereg = 'tm'; $str = 'hello,tm,Tm,tM,TM.'; $rep_str = eregi_replace($ereg, 'TM', $str) ...
- Unity3D中的工具类
1.时间:Unity提供了Time类,这个类主要用来获取当前的系统时间. Time.time:从游戏开始后开始计时,表示截止目前共运行的游戏时间. Time.deltaTime:获取Update()方 ...
- Android文件下载(实现断点续传)
本文将介绍在android平台下如何实现多线程下载,大家都知道,android平台使用java做为开发语言,所以java中支持的多线程下载方式在android平台下都支持,其中主要有两种方式可以实现多 ...
- Xmind 快捷键
Xmind 快捷键 快捷键(Windows) 快捷键(Mac) 描述 Ctrl+N Command+N 建立新工作簿 Ctrl+O Command+O 开启工作簿 Ctrl+S Command+S 储 ...
- pmp论坛
PMP论坛: http://www.px101.com/specialpmp/ http://www.pmp.cn/ http://www.pmptuan.com/ http://www.mypm.n ...
- Entify Framewrok - Join的使用方法
问题:有2个表,使用id相连,如何用Join语法将其连接起来? 如下代码 List<tblAssociation> assoList = dataContext.tblAssociatio ...