• plupload 如何控制最小宽度和文件类型及跨域


    直接上代码

    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_ 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

    2.跨域

    在iis7下web.config配置,实际配置时,指定具体的域名,防止被黑客入侵

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
     <system.webServer>
       <httpProtocol>
         <customHeaders>
           <add name="Access-Control-Allow-Origin" value="*" />
         </customHeaders>
       </httpProtocol>
     </system.webServer>
    </configuration>

    3.php怎么跨域

    在文件头部加上  header( 'Access-Control-Allow-Origin:http://abc.com' );

    如果在iis下不要添加,如2配置即可

    跨域可能用的路径

    //获取当前的域名:  
    echo $_SERVER['SERVER_NAME'];  
    //获取来源网址,即点击来到本页的上页网址  
    echo $_SERVER["HTTP_REFERER"];  
    $_SERVER['REQUEST_URI'];//获取当前域名的后缀  
    $_SERVER['HTTP_HOST'];//获取当前域名  
    dirname(__FILE__);//获取当前文件的物理路径  
    dirname(__FILE__)."/../";//获取当前文件的上一级物理路径  
  • 相关阅读:
    老王讲架构:负载均衡
    支付宝系统架构内部剖析
    Effective Java 第三版——61. 基本类型优于装箱的基本类型
    Effective Java 第三版——60. 需要精确的结果时避免使用float和double类型
    Effective Java 第三版——59. 熟悉并使用Java类库
    Effective Java 第三版——58. for-each循环优于传统for循环
    Effective Java 第三版——57. 最小化局部变量的作用域
    Effective Java 第三版——56. 为所有已公开的API元素编写文档注释
    Effective Java 第三版——55. 明智而审慎地返回Optional
    Effective Java 第三版——54. 返回空的数组或集合不要返回null
  • 原文地址:https://www.cnblogs.com/xcsn/p/5764241.html
Copyright © 2020-2023  润新知