码迷,mamicode.com
首页 > 其他好文 > 详细

plupload 如何控制最小宽度和文件类型

时间:2016-08-12 13:18:22      阅读:1171      评论:0      收藏:0      [点我收藏+]

标签:

直接上代码

plupload.addFileFilter(‘min_width‘, function (maxwidth, file, cb) {
        var self = this, img = new o.Image(); 
        function finalize(result) {
            // cleanup
            img.destroy();
            img = null;

            // if rule has been violated in one way or another, trigger an error
            if (!result) {
                self.trigger(‘Error‘, {
                    code: plupload.IMAGE_DIMENSIONS_ERROR,
                    message: "图片宽度不能小于" + maxwidth + "px",
                    file: file
                });
            }
            cb(result);
        }
        img.onload = function () {
            // check if resolution cap is not exceeded
            finalize(img.width >= maxwidth);
        };
        img.onerror = function () {
            finalize(false);
        };
        img.load(file.getSource());
    });
    plupload.addFileFilter(‘filetype‘, function (filetype, file, cb) {
        var self = this, img = new o.Image();
        function finalize(result) {
            // cleanup
            img.destroy();
            img = null;

            // if rule has been violated in one way or another, trigger an error
            if (!result) {
                self.trigger(‘Error‘, {
                    code: plupload.IMAGE_DIMENSIONS_ERROR,
                    message: "您上传的图片格式是" + file.type + ",只能上传jpg图片",
                    file: file
                });
            }
            cb(result);
        }
        img.onload = function () {
            // check if resolution cap is not exceeded
            var type = file.type; 
            type = type.replace("image/", ""); 
            finalize(filetype.indexOf(type) > 0);  
        };
        img.onerror = function () {
            finalize(false);
        };
        img.load(file.getSource()); 
    });


    var uploader = new plupload.Uploader({//创建实例的构造方法
        browse_button: ‘fileinput-button‘,
        runtimes: ‘html5,flash,silverlight,html4‘, //上传插件初始化选用那种方式的优先级顺序 
        url: "/common/ImageUp", //远程上传地址
        max_file_size: ‘20mb‘,
        chunk_size: ‘500kb‘, 
        filters:  
           { title: "Image files", filetype: "jpg,jpeg", min_width: 600 }
        ,
        flash_swf_url: ‘/Scripts/plupload-2.1.9/Moxie.swf‘, 
    });

    uploader.init();

 

参考文章:

http://stackoverflow.com/questions/14091505/control-image-width-and-height-when-upload-image

 

plupload 如何控制最小宽度和文件类型

标签:

原文地址:http://www.cnblogs.com/xcsn/p/5764241.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!