走进一步,发掘一处。勇于,敢于。
jtans

导航

 
 var uploader = new plupload.Uploader({
            runtimes : 'html5,flash,html4',
            browse_button : 'pickfiles',
            container : 'container',
            max_file_size : '20mb',
	        url :uploadUrl,
            flash_swf_url : 'flash/plupload.flash.swf',
            filters : [
                {title : "课件文档", extensions : "docx,pptx,xlsx,doc,dox,ppt,ppx,xls,dox,ppt,ppx,pdf,swf,flv,mp4,3gp"}
            ],
            resize : {width : 320, height : 240, quality : 90},
            multipart_params: {
	            callback:"?",
	            desc:"",  
	            name:""
            }
        });
        uploader.bind('Init', function(up, params) {
            $('#filelist').html('<tr><th width="146">文件名</th>'+
                '<th width="281">进度</th><th width="78">文档大小</th>'+
                '<th width="159">我的定价</th><th width="97" class="kt_thlast">操作</th></tr>');
        });
        $('#uploadfiles').click(function(e) {
	        var msg = '';
	        $('tr[resourcename]').find('a[uploadcmd=set]').each(function(i,v){
		        if($(this).attr('class')!='selected')
		            msg +=i+1+';';
	        });
	        if(msg.replace(/;/ig,'').length>0){
		        ns.Msg('请设置文件第:'+msg+'的课件属性');
	        }else if(uploader.files.length<=0){
		        ns.Msg('请添加要上传的文件。');
	        }
	        else{
		        uploader.start();
		        e.preventDefault();
	        }

        });
        uploader.init();
        uploader.bind('FilesAdded', function(up, files) {
	        $('#kt_uploadMadeList').hide();
	        $('#kt_uploadmadefiles').hide();
	        $('#kt_uploadFileList').show();
	        $('#uploadfiles').show();
	        var zerofilename = new Array();
	        var tooLargeFileName = new Array();
	        $.each(files, function(i, file) {
		        if (file.size == 0)
			        zerofilename.push(file.name);
		        else if(UploadInfo.maxSingleSize > 0 && file.size > UploadInfo.maxSingleSize)
			        tooLargeFileName.push(file.name);
	        });

	        if (zerofilename.length == 0 && tooLargeFileName.length == 0) {
		        var totalSize = up.total.size;
		        $.each(files, function(i, file) {
			        totalSize += file.size;
		        });

		        if ( totalSize <= UploadInfo.maxSize) {
			        $.each(files, function(i, file) {debugger;
				      //  if($('tr[resourcename]').length < UploadInfo.maxCount){
					        addPhotoInfo(
						        file,
						        function(fileId) {
							        var fileinfo = uploader.getFile(fileId);
							        if (fileinfo) {
								        if (fileinfo.status != plupload.UPLOADING) {
									        uploader.removeFile(fileinfo);
								        } else if (fileinfo.status == plupload.UPLOADING) {
									        uploader.stop();
									        uploader.removeFile(fileinfo);
									        uploader.start();
								        }
							        }
						        }
					        );
					        // $('#photo_uploadPhoto_startUpload').parent().removeClass("unablepic");
					        refreshUploadingProgress();
				        /*}else{
					        AlertMessage('一次只能上传'+UploadInfo.maxCount+'个文件。');
				        }*/

			        });
		        }
		        else {
			        $.each(files, function(i, file) {
				        up.removeFile(file);
			        });
			        AlertMessage("您上传的附件已经超出了 " +plupload.formatSize(UploadInfo.maxSize )+ "的附件总大小限制,请减少附件上传数量");
		        }
	        }
	        else {
		        $.each(files, function(i, file) {
			        up.removeFile(file);
		        });

		        var alertMessage = '';
		        if(zerofilename.length > 0)
			        alertMessage += zerofilename.join(",") + " 的大小为0" + tooLargeFileName.length > 0 ? "," : "";
		        if(tooLargeFileName.length > 0)
			        alertMessage += tooLargeFileName.join(",") + " 的大小大于" + plupload.formatSize(UploadInfo.maxSingleSize );

		        alertMessage += ",请重新选择文件上传。"

		       AlertMessage(alertMessage);
	        }
            //up.refresh(); // Reposition Flash/Silverlight
        });
	    uploader.bind("BeforeUpload", function(up, file) {
		    var fileInfo = getResourceInfo(file.id);
		    up.settings.multipart_params.resourceName = fileInfo.resourceName;
		    up.settings.multipart_params.gradeids = fileInfo.gradeids;
		    up.settings.multipart_params.courseids = fileInfo.courseids;
		    up.settings.multipart_params.tag = fileInfo.tag;
		    up.settings.multipart_params.price = fileInfo.price;
		    up.settings.multipart_params.desc = fileInfo.desc;
		    up.settings.multipart_params.keyword = fileInfo.keyword;
		    refreshFileStatus(file);
		    refreshUploadingProgress();
	    });
        uploader.bind('UploadProgress', function(up, file) {
	        refreshFileStatus(file);
	        refreshUploadingProgress();
        });
        uploader.bind('Error', function(up, err) {
            //$('#' + file.id + " td:eq(1)").append(" Error: " + err.code + ", Message: " + err.message );
	        refreshFileStatus(err.file);
	        refreshUploadingProgress();
        });
        uploader.bind('FileUploaded', function(up, file) {
	        refreshFileStatus(file);
	        refreshUploadingProgress();
        });
	    uploader.bind('UploadComplete', function(up, files) {
                 //上传完毕的处理。。。。
		   // $('#filelist td[name=cancelbtn] a').hide();
		    //alert('aaaaa');
		   
		    $('tr[aa]').remove();
	    });                

  

posted on 2012-11-06 16:19  jtans  阅读(468)  评论(0)    收藏  举报