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 ...
随机推荐
- C 语言字符 和字符串输出
int main(void){ char ch; char str[80]; printf("Input a string: "); //先输入字符串 gets(str);/ ...
- IOS多线程 总结 -------------核心代码(GCD)
//NSObject //在子线程中执行代码 // 参数1: 执行的方法 (最多有一个参数,没有返回值) //参数2: 传递给方法的参数 [self performSelectorInBackgrou ...
- lpc1788控制步进电机28BYJ-48
下面直接上代码: #include "lpc177x_8x.h" #include "lpc177x_8x_clkpwr.h" #include "l ...
- cf Sereja and Array
http://codeforces.com/contest/315/problem/B #include <cstdio> #include <cstring> #includ ...
- 为什么memset的第二个参数不把int替换成char
memset是一个经常被用来初始化数组的函数,其定义如下: 1 void * memset ( void * ptr, int value, size_t num ); 它的效果大致是把以ptr为起始 ...
- NSIS脚本调用C语言写的插件
其实NSIS的官网已经提供了很多别人开发的插件了,今天需要用到GetVersion这个插件,这是不维护的插件了,不推荐用,但是由于现实中的问题,导致我不得不用这个插件. 所以就下载下来了. 下载下来之 ...
- BZOJ2212: [Poi2011]Tree Rotations
2212: [Poi2011]Tree Rotations Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 391 Solved: 127[Submi ...
- 读书笔记:java特种兵(上)
----看着样章,感觉还不错,就买下来了,书先不论好坏,悟到了一个道理,东西没有好与坏,只有适不适合. 第一章:想了解编译器是如何优化程序的,当年的编译原理没有学好啊
- Ugly Number II 解答
Question Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime ...
- 深入super,看Python如何解决钻石继承难题
1. Python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通方法和super方法 假设Base是基类 class Base(object): def __init_ ...