直接上代码
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
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__)."/../";//获取当前文件的上一级物理路径