uploadify 上传

本来想做一套上传公用的组建的,里面包含文件转码等功能,看来这些都只能后来一步一步加上了,先写下来。。。

1,引入脚本等

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Index</title>
    <link href="/uploadify/uploadify.css" rel="stylesheet" />
</head>
<body>
    <input type="file" name="upload" id="upload" />
</body>
</html>
<script src="/Scripts/jquery-1.11.1.min.js"></script>
<script src="/uploadify/jquery.uploadify.min.js"></script>
<script>
    $(function () {
        $(‘#upload‘).uploadify({
            ‘formData‘: { ‘folder‘: ‘d:\\‘ },
            ‘buttonText‘: ‘选择文件‘,
            ‘buttonClass‘: ‘browser‘,
            ‘removeCompleted‘: false,
            ‘swf‘: ‘/uploadify/uploadify.swf‘,
            ‘uploader‘: ‘/FileUp/Upload‘,
            ‘fileSizeLimit‘:‘500MB‘,
            ‘onError‘: function (event, id, fileObj, errorObj) {
                if (errorObj.type === "File Size") {
                    alert(‘超过文件上传大小限制(2M)!‘);
                    return;
                }
                alert(errorObj.type + ‘, Error: ‘ + errorObj.info);
            },
        });
    });
</script>

2,后台上传代码

 public class FileUpController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ContentResult Upload(HttpPostedFileBase fileData, string folder)
        {
            string filename = "";
            if (null != fileData)
            {
                var length = fileData.ContentLength;
                try
                {
                    filename = Path.GetFileName(fileData.FileName); //获得文件名
                    saveFile(fileData, folder, filename);
                }
                catch (Exception ex)
                {
                    filename = ex.ToString();
                }
            }
            return Content(filename);
        }

        [NonAction]
        private bool saveFile(HttpPostedFileBase postedFile, string filepath, string saveName)
        {
            bool result = false;
            if (!Directory.Exists(filepath))
            {
                Directory.CreateDirectory(filepath);
            }
            try
            {
                postedFile.SaveAs(Path.Combine(filepath, saveName));
                result = true;
            }
            catch (Exception e)
            {
                throw new ApplicationException(e.Message);
            }
            return result;
        }
    }

3,设置web.config(在system.web节点中)

    <httpRuntime requestLengthDiskThreshold="256" maxRequestLength="2097151"/>   //假如超过256kb文件,其将缓存到硬盘

  

时间: 2024-08-10 23:31:00

uploadify 上传的相关文章

Uploadify上传,可以上传多个文件,带有进度条,希望有所帮助!

原文:Uploadify上传,可以上传多个文件,带有进度条,希望有所帮助! 源代码下载:http://www.zuidaima.com/share/1550463502568448.htm 上传前 上传后 

C# uploadify 上传 -220 IO Error 问题

1. 前端: uploadify 上文件大小限制配置. 2. 后端: web.config 配置 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0"/> <httpRuntime maxRequestLength="10240"

ASP.NET Uploadify 上传文件过大报错

Uploadify上传文件原来很早之前用过,没发现什么问题.今天再使用过程中,当文件大于30M的时候就会报错404.查看错误消息提示配置最大上传太小了.需要修改. 记得原来配置上传文件大小在这里:<httpRuntime maxRequestLength="2097100" executionTimeout="3600"/> 配置即可.可是当我这里修改了之后发现还是错误.就想是不是上传控件本身有限制,看到我的有limitSize:30 已经设置了大小,但

MVC3+jquery Uploadify 上传文件

最近做项目用到了上传图片的功能,以前也写过这类代码,不过都是用传统的file标签,今天整理一个好用的插件Uploadify..都做了一些注释,一看便知. 可以去官网下载最新的:Uploadify下载地址:http://www.uploadify.com/download/ 1.引用文件 <link href="@Url.Content("~/Scripts/uploadify/uploadify.css")" rel="stylesheet"

[Plugin] JQuery.uploadify上传文件插件的使用详解For ASP.NET

URL:http://www.cnblogs.com/xiaopin/archive/2010/01/21/1653523.html 今天下午整理文件上传的例子,感觉收集到的例子都很不人性话,后来找到一个还可以的,本来想改成类似于腾讯QQ相册那种方式,仔细看了一下是Flash的, 而且那个极速上传插件也不知道用什么做的?问了一下,说是什么cgi. 搞得一头雾水! 后来朋友推荐了一个这个叫uploadify的上传插件,似乎挺好,就到官方下了个示例运行,感觉挺好,自己再稍加美化一下就OK 了..!

(网上看的)asp.net使用uploadify上传出现的IO Error问题

解决方法: 1.uploadify控件的自定义size必须调整大小,即属性:sizeLimit:'300000000000' //根据自己需要 2.asp.net中webconfig用记事本打开,插在<system.web></system.web>之间, “<httpRuntime maxRequestLength="2097151" executionTimeout="50000" />” maxRequestLength大小

基于thinkphp的uploadify上传图功能

php Action server端 <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * Description of UploadAction * * @author hxwj */ class UploadAction extends CommonAction{ public function _initialize(){ //

解决Uploadify上传控件加载导致的GET 404 Not Found问题

今天在项目发用到Uploadify上传, 发现在打开页面时会有一多余的请求,由于路由没有设置这个,导致404错误,能搜索查到以下解决的方法 <Uploadify v3 bug. Unecessary request when there is no button_image_url set.>找到了解决的办法 在原文件中修改 将下面代码: this.settings.button_image_url = SWFUpload.completeURL(this.settings.button_im

文件上传~Uploadify上传控件~续(多文件上传)

对于Uploadify文件上传之前已经讲过一次(文件上传~Uploadify上传控件),只不过没有涉及到多文件的上传,这回主要说一下多个文件的上传,首先,我们要清楚一个概念,多文件上传前端Uploadify是通过轮训的方式去调用我们的后台upload程序的,所以,对于多文件上传来说,也没什么稀奇的. 下面是文件上传后的缩略图如下 列表的组装使用JS模板,这样对于复杂的HTML结构来说,可以减少拼写错误的出现,关闭是将LI元素从UI元素移除,最后提交时,从UI里检查LI元素,然后对它进行组装,并进

uploadify上传控件中文的乱码解决办法

网站用的gb2312的编码,用uploadify上传控件上传中文时在IE能部分成功,FF,Chrome则完全失败,查找了一天原因,结果发现是页面编码问题,网上说uploadify的flash是采用utf-8的编码方式. 所以上传后会出现文件名乱码的问题. 最终解决问题的方法是: 在UploadHandler.ashx里面直接加上下面几句就可以了,也不用在config里面去设置什么. public void ProcessRequest(HttpContext context) { context