直接上代碼
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__)."/../";//獲取當前文件的上一級物理路徑