jquery-uploadifyv3.2.1 文件上传插件 学习
先认识一下他的属性。
var settings = $.extend({ // Required Settings,这3个必须的咯。 id : $this.attr('id'), // The ID of the DOM object,ID swf : 'uploadify.swf', // SWF file 路径 uploader : 'uploadify.php', // 服务器处理路径 // Options,下面是可设置的属性 auto : true, // Automatically upload files when // added to the queue,是否添加以后就自动上传。 buttonClass : '', // A class name to add to the // browse button DOM object buttonCursor : 'hand', // The cursor to use with // the browse button buttonImage : null, // (String or null) The path to // an image to use for the Flash // browse button if not using // CSS to style the button buttonText : 'SELECT FILES', // The text to use // for the browse // button 文件上传的名字 checkExisting : false, // The path to a server-side // script that checks for // existing files on the // server,判断是否已存在相应文件 debug : false, // Turn on swfUpload debugging mode fileObjName : 'Filedata', // The name of the file // object to use in your // server-side script,对应request的name是什么 ** fileSizeLimit : 0, // The maximum size of an // uploadable file in KB // (Accepts units B KB MB GB if // string, 0 for no limit) 文件大小限制,0表示不限制。 fileTypeDesc : 'All Files', // The description for // file types in the // browse dialog 文件描述 fileTypeExts : '*.*', // Allowed extensions in the // browse dialog // (server-side validation // should also be used),允许的扩展类型 height : 30, // The height of the browse button,按钮高度 itemTemplate : false, // The template for the file // item in the queue method : 'post', // The method to use when // sending files to the // server-side upload script,提交方法,默认为post multi : true, // Allow multiple file selection in // the browse dialog,是否允许多文件选择,默认为true formData : {}, // An object with additional data to // send to the server-side upload // script with every file upload preventCaching : true, // Adds a random value to // the Flash URL to prevent // caching of it (conflicts // with existing parameters) progressData : 'percentage', // ('percentage' or // 'speed') Data to // show in the queue // item during a // file upload queueID : false, // The ID of the DOM object to // use as a file queue (without // the #),文件队列。 queueSizeLimit : 999, // The maximum number of // files that can be in the // queue at one time removeCompleted : true, // Remove queue items from // the queue when they are // done uploading,完成以后自动移除。 removeTimeout : 3, // The delay in seconds before // removing a queue item if // removeCompleted is set to // true,移出的时间 requeueErrors : false, // Keep errored files in the // queue and keep trying to // upload them,保持错误的文件在队列里面,并可以重新上传 successTimeout : 30, // The number of seconds to // wait for Flash to detect // the server's response // after the file has // finished uploading,完成以后等待服务器30秒 uploadLimit : 0, // The maximum number of files // you can upload,上传限制。 width : 120, // The width of the browse button,按钮宽度 // Events,重载的事件,不重载的话,则会执行自己的再执行原生的 overrideEvents : [] }, options);
2.接着是他的事件
onCancel :function(file){}//取消方法 onClearQueue onDestroy onDialogClose onDialogOpen onDisable onEnable onFallback onInit onQueueComplete onSelect onSelectError onSWFReady
//上传完成 onUploadComplete: function(file) {alert('The file ' + file.name + ' finished processing.'); }
onUploadError
onUploadProgress
onUploadStart
onUploadSuccess
方法:
$('#file_upload').uploadify('cancel',"*"); // 有*的话,则队列里的所有会 // 删掉或上传,没有则作用于 // 第一个 $('#file_upload').uploadify('upload','*'); $('#file_upload').uploadify('stop'); $('#file_upload').uploadify('settings','buttonText','BROWSE'); $('#file_upload').uploadify('disable', true); // true - disable,false - enable $('#file_upload').uploadify('destroy');