Asp.Net+flash as3 文件上传实现进度条代码片段
UpFile.Fla (flash文件)
以下是代码片段: fileRefListener.onSelect = function (fileRefList:FileReferenceList):Void { uploadBtn.enabled = true; rePaintProBar("progressBar", 18.0, 50.0); var list:Array = fileRefList.fileList; var fileRef:FileReference; totalBytes = 0; for(var i:Number = 0; i < list.length; i++) { fileRef = list[i]; totalBytes += fileRef.size; txtFilePath.text = fileRef.name; FileExt = fileRef.type; } } fileRefListener.onCancel = function (fileRef:FileReference):Void { uploadBtn.enabled = false; } fileRefListener.onOpen = function (fileRef:FileReference):Void { txt_FilePath.label = fileRef.name; } fileRefListener.onProgress = function (fileRef:FileReference, bytesLoaded:Number, bytesTotal:Number):Void { progressBar.mode = "manual"; var temp:Number = bytesLoaded - uploadedBytes2[fileRef.name] uploadedBytes2[fileRef.name] = bytesLoaded; uploadedBytes += temp; progressBar.setProgress(uploadedBytes, totalBytes); txtUploaded.text = GetSizeType(uploadedBytes); txtTotal.text = GetSizeType(totalBytes); } fileRefListener.onComplete = function (fileRef:FileReference):Void { filesCompleted++; if(filesCompleted == totalFiles) FinishedUpload(); } fileRefList.addListener(fileRefListener); browseButn.clickHandler = function () { fileRefList.browse(allTypes); } uploadBtn.clickHandler = function () { var list:Array = fileRefList.fileList; var fileRef:FileReference; if(uploadBtn.label == "上传") { browseBtn.enabled = false; uploadBtn.label = "取消"; totalFiles = list.length; filesCompleted = 0; uploadedBytes = 0; uploadedBytes2 = []; txtUploadNum.text = "已上传:"; txtFileTotal.text = "文件大小:"; for(var i:Number = 0; i < list.length; i++) { fileRef = list[i]; fileRef.addListener(fileRefListener); uploadedBytes2[fileRef.name] = 0; if(uploadPage != undefined) fileRef.upload(uploadPage); } } else { for(var i:Number = 0; i < list.length; i++) { fileRef = list[i]; fileRef.cancel(); } uploadBtn.label = "上传"; browseBtn.enabled = true; } } |
UpLoadFile.aspx
以下是代码片段: string saveToFolder = "/UpFile/"; HttpFileCollection uploadedFiles = Request.Files; string NewFileName = Session["UpLoadFileName"].ToString(); string Path = Server.MapPath(saveToFolder); for (int i = 0; i < uploadedFiles.Count; i++) { HttpPostedFile F = uploadedFiles[i]; if (uploadedFiles[i] != null && F.ContentLength > 0) { string newName = F.FileName.Substring(F.FileName.LastIndexOf("\") + 1); F.SaveAs(Path + "/" + NewFileName + F.FileName.Substring(F.FileName.LastIndexOf("."))); } } |