用C#写上传文件(100M左右)的程序到100m服务器器,需要实现上传百分比、上传进度和断点续传,

使用C#的Winform实现远程服务器上传
使用C#的Winform实现远程服务器上传&&
方案1:上传到IIS服务器.要开启虚拟目录的“写入”权限,要不然就报 403 错误
先把IIS服务扩展中的WebDev打开,然后IIS站点添加MIME  txt类型 常见的MIME类型如下
超文本标记语言文本 .html,.html text/html
普通文本 .txt text/plain
RTF文本 .rtf application/rtf
GIF图形 .gif image/gif
JPEG图形 .ipeg,.jpg image/jpeg
au声音文件 .au audio/basic
MIDI音乐文件 mid,.midi audio/midi,audio/x-midi
RealAudio音乐文件 .ra, .ram audio/x-pn-realaudio
MPEG文件 .mpg,.mpeg video/mpeg
AVI文件 .avi video/x-msvideo
GZIP文件 .gz application/x-gzip
TAR文件 .tar application/x-tar
再然后设置目标文件夹的可写性
using System.Collections.G
using System.T
using System.N
using System.IO;
namespace Common
/// &summary&
/// winform形式的文件传输类
/// &/summary&
public class WinFileTransporter
/// &summary&
/// WebClient上传文件至服务器,默认不自动改名
/// &/summary&
/// &param name=&fileNamePath&&文件名,全路径格式&/param&
/// &param name=&uriString&&服务器文件夹路径&/param&
public void UpLoadFile(string fileNamePath, string uriString)
UpLoadFile(fileNamePath, uriString, false);
/// &summary&
/// WebClient上传文件至服务器
/// &/summary&
/// &param name=&fileNamePath&&文件名,全路径格式&/param&
/// &param name=&uriString&&服务器文件夹路径&/param&
/// &param name=&IsAutoRename&&是否自动按照时间重命名&/param&
public void UpLoadFile(string fileNamePath, string uriString, bool IsAutoRename)
string fileName = fileNamePath.Substring(fileNamePath.LastIndexOf(&\\&) + 1);
string NewFileName = fileN
if (IsAutoRename)
NewFileName = DateTime.Now.ToString(&yyMMddhhmmss&) + DateTime.Now.Millisecond.ToString() + fileNamePath.Substring(fileNamePath.LastIndexOf(&.&));
string fileNameExt = fileName.Substring(fileName.LastIndexOf(&.&) + 1);
if (uriString.EndsWith(&/&) == false) uriString = uriString + &/&;
uriString = uriString + NewFileN
Utility.LogWriter log = new Utility.LogWriter();
//log.AddLog(uriString, &Log&);
//log.AddLog(fileNamePath, &Log&);
/// 创建WebClient实例
WebClient myWebClient = new WebClient();
myWebClient.Credentials = CredentialCache.DefaultC
// 要上传的文件
FileStream fs = new FileStream(fileNamePath, FileMode.Open, FileAccess.Read);
//FileStream fs = OpenFile();
BinaryReader r = new BinaryReader(fs);
byte[] postArray = r.ReadBytes((int)fs.Length);
Stream postStream = myWebClient.OpenWrite(uriString, &PUT&);
//使用UploadFile方法可以用下面的格式
//myWebClient.UploadFile(uriString,&PUT&,fileNamePath);
if (postStream.CanWrite)
postStream.Write(postArray, 0, postArray.Length);
postStream.Close();
fs.Dispose();
log.AddLog(&上传日志文件成功!&, &Log&);
postStream.Close();
fs.Dispose();
log.AddLog(&上传日志文件失败,文件不可写!&, &Log&);
catch (Exception err)
postStream.Close();
fs.Dispose();
//Utility.LogWriter log = new Utility.LogWriter();
log.AddLog(err, &上传日志文件异常!&, &Log&);
postStream.Close();
fs.Dispose();
/// &summary&
/// 下载服务器文件至客户端
/// &/summary&
/// &param name=&URL&&被下载的文件地址,绝对路径&/param&
/// &param name=&Dir&&另存放的目录&/param&
public void Download(string URL, string Dir)
WebClient client = new WebClient();
string fileName = URL.Substring(URL.LastIndexOf(&\\&) + 1);
//被下载的文件名
string Path = Dir + fileN
//另存为的绝对路径+文件名
Utility.LogWriter log = new Utility.LogWriter();
WebRequest myre = WebRequest.Create(URL);
catch (Exception err)
//MessageBox.Show(exp.Message,&Error&);
log.AddLog(err, &下载日志文件异常!&, &Log&);
client.DownloadFile(URL, fileName);
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
byte[] mbyte = r.ReadBytes((int)fs.Length);
FileStream fstr = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.Write);
fstr.Write(mbyte, 0, (int)fs.Length);
fstr.Close();
catch (Exception err)
//MessageBox.Show(exp.Message,&Error&);
log.AddLog(err, &下载日志文件异常!&, &Log&);
第二种方案:
相信用ASP.NET写一个上传文件的网页,大家都会写,但是有没有人想过通过在中通过HTTP协议上传文件呢?
有些人说要向服务器端上传文件,用FTP协议不是很简单吗?效率又高,为什么还要使用HTTP协议那么麻烦呢?这里面有几个原因:
(1)FTP服务器的部署相对麻烦,还要设置权限,权限设置不对,还会惹来一系列的安全问题。
(2)如果双方都还有防火墙,又不想FTP相关的一些端口时,HTTP就会大派用场,就像 Services能穿透防火墙一样。
(3)其他的…,还在想呢…
但是使用HTTP也有他的一些问题,例如不能断点续传,大文件上传很难,速度很慢,所以HTTP协议上传的文件大小不应该太大。
说了这么多,原归正传,一般来说,在Winform里通过HTTP上传文件有几种可选的方法:
(1)前面提到的Web Services,就是一种很好的方法,通过编写一个WebMethod,包含有 byte[] 类型的参数,然后调用Web Services的方法,文件内容就会以Base64传到服务器上,然后重新保存即可。
[WebMethod]
public void UploadFile(byte[] content,string filename){
Stream sw = new StreamWriter(...);
sw.Close();
当然,这种通过Base64的方法效率比较低,那么可以采用WSE,支持附件,并以2进制形式传送,效率会更高。
(2)除了通过,另外一种更简单的方法就是通过WebClient或者HttpWebRequest来模拟HTTP的POST动作来实现。这时候首先需要编写一个asp.net web form来响应上传,代码如下:
&%@ Page language=&c#& Codebehind=&WebForm1.aspx.cs& AutoEventWireup=&false& Inherits=&UploadFileWeb.WebForm1& %&
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.0 Transitional//EN& &
&title&WebForm1&/title&
&meta name=&GENERATOR& Content=&Microsoft Visual Studio .NET 7.1&&
&meta name=&CODE_LANGUAGE& Content=&&&
&meta name=&vs_defaultClientScript& content=&JavaScript&&
&meta name=&vs_targetSchema& content=&/intellisense/ie5&&
&form id=&Form1& method=&post& runat=&server&&
using System.C
using ponentM
using System.D
using System.D
using System.W
using System.Web.SessionS
using System.Web.UI;
using System.Web.UI.WebC
using System.Web.UI.HtmlC
namespace UploadFileWeb
/// &summary&
/// WebForm1 的摘要说明。
/// &/summary&
public class WebForm1 : System.Web.UI.Page
private void Page_Load(object sender, System.EventArgs e)
// 在此处放置用户代码以初始化页面
foreach( string f in Request.Files.AllKeys)
HttpPostedFile file = Request.Files[f];
file.SaveAs(@&D:\Temp\& + file.FileName);
if( Request.Params[&testKey&] != null )
Response.Write(Request.Params[&testKey&]);
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InitializeComponent();
base.OnInit(e);
/// &summary&
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// &/summary&
private void InitializeComponent()
this.Load += new System.EventHandler(this.Page_Load);
#endregion
其实这个页面跟我们平常写的asp.net上传文件代码是一样的,在Web 页的Request对象中包含有Files这个对象,里面就包含了通过POST方式上传的所有文件的信息,这时所需要做的就是调用 Request.Files[i].SaveAs方法。
但是怎么让才能在里面模拟想Web Form POST 数据呢?System.Net命名空间里面提供了两个非常有用的类,一个是WebClient,另外一个是HttpWebRequest类。如果我们不需要通过代理服务器来上传文件,那么非常简单,只需要简单的调用WebClient.UploadFile方法就能实现上传文件:
private void button1_Click(object sender, System.EventArgs e)
WebClient myWebClient = new WebClient();
myWebClient.UploadFile(&http://localhost/UploadFileWeb/WebForm1.aspx&,&POST&,@&D:\30c.org.txt&);
你可能喜欢
""].join(""));18009人阅读
基于Ajax的文件上传要实现的功能要求,要在用户提交了上传按钮请求后,客户端其页面要显示文件上传进度条。
&&&&& 其整个功能时序图如图所示。
&简单的说,要实现在客户端显示进度条,需要做的是:当客户端提交上传文件请求后,服务器在上传文件的过程中,将上传进度情况保存到Session中,客户端周期性的发送请求来获取保存在Session中值,以获取上传文件的进度信息。
1.&新建web工程AjaxUpload。
2.&将commons-fileupload-1.2.1-bin.zip包中的commons-fileupload-1.2.1.jar文件和commons-io-1.4-bin.zip包中的commons-io-1.4.jar文件拷贝到web工程下的WEB-INF\lib目录下。
3.&由于本实例涉及到多个类,处理此类问题最好是给相应的类打包进行管理。在web工程src目录下新建一个包com.ncu.upload。
4.&服务器端实现。
首先要创建一个用来保存文件上传状态的类&FileUploadStatus。其源码如下:
package com.ncu.
import java.util.*;
public class FileUploadStatus {
//上传总量
private long uploadTotalSize=0;
//读取上传总量
private long readTotalSize=0;
//当前上传文件号
private int currentUploadFileNum=0;
//成功读取上传文件数
private int successUploadFileCount=0;
private String status=&&;
//处理起始时间
private long processStartTime=0l;
//处理终止时间
private long processEndTime=0l;
//处理执行时间
private long processRunningTime=0l;
//上传文件URL列表
private List uploadFileUrlList=new ArrayList();
//取消上传
private boolean cancel=
//上传base目录
private String baseDir=&&;
public String getBaseDir() {
return baseD
public void setBaseDir(String baseDir) {
this.baseDir = baseD
public boolean getCancel() {
public void setCancel(boolean cancel) {
this.cancel =
public List getUploadFileUrlList() {
return uploadFileUrlL
public void setUploadFileUrlList(List uploadFileUrlList) {
this.uploadFileUrlList = uploadFileUrlL
public long getProcessRunningTime() {
return processRunningT
public void setProcessRunningTime(long processRunningTime) {
this.processRunningTime = processRunningT
public long getProcessEndTime() {
return processEndT
public void setProcessEndTime(long processEndTime) {
this.processEndTime = processEndT
public long getProcessStartTime() {
return processStartT
public void setProcessStartTime(long processStartTime) {
this.processStartTime = processStartT
public long getReadTotalSize() {
return readTotalS
public void setReadTotalSize(long readTotalSize) {
this.readTotalSize = readTotalS
public int getSuccessUploadFileCount() {
return successUploadFileC
public void setSuccessUploadFileCount(int successUploadFileCount) {
this.successUploadFileCount = successUploadFileC
public int getCurrentUploadFileNum() {
return currentUploadFileN
public void setCurrentUploadFileNum(int currentUploadFileNum) {
this.currentUploadFileNum = currentUploadFileN
public String getStatus() {
public void setStatus(String status) {
this.status =
public long getUploadTotalSize() {
return uploadTotalS
public void setUploadTotalSize(long uploadTotalSize) {
this.uploadTotalSize = uploadTotalS
&由于要在客户端要显示进度条,所以在上传过程中服务器端需要监视和维护上传状态的信息,此过程需要处理的数据信息是:不断更新Session中保存的FileUploadStatus实例的信息,如:已经上传的字节数,上传文件的总大小等。FileUpload现在的1.2版本为监视上传进度提供了内建的支持,可以直接继承类ProgressListener,然后重载update()方法,在该方法中添加自己要处理的代码,最后在文件上传处理代码(后面会讲到)中通过为ServletFileUpload对象注册创建的监听类。监听类UploadListener的源代码如下:
package com.ncu.
import javax.servlet.http.HttpS
import mons.fileupload.ProgressL
public class UploadListener implements ProgressListener {
private HttpSession session=
public UploadListener (HttpSession session){
this.session=
* 更新状态
* @param pBytesRead 读取字节总数
* @param pContentLength 数据总长度
* @param pItems 当前正在被读取的field号
public void update(long pBytesRead, long pContentLength, int pItems) {
FileUploadStatus fuploadStatus = UploadServlet.takeOutFileUploadStatusBean(this.session);
fuploadStatus.setUploadTotalSize(pContentLength);
//读取完成
if (pContentLength == -1) {
fuploadStatus.setStatus(&完成对& + pItems + &个文件的读取:读取了 & + pBytesRead + &/&
+ pContentLength+ & bytes.&);
fuploadStatus.setReadTotalSize(pBytesRead);
fuploadStatus.setCurrentUploadFileNum(pItems);
fuploadStatus.setProcessEndTime(System.currentTimeMillis());
fuploadStatus.setProcessRunningTime(fuploadStatus.getProcessEndTime());
}else{//读取过程中
fuploadStatus.setStatus(&当前正在处理第& + pItems+&个文件:已经读取了 & + pBytesRead + & / & + pContentLength+ & bytes.&);
fuploadStatus.setReadTotalSize(pBytesRead);
fuploadStatus.setCurrentUploadFileNum(pItems);
fuploadStatus.setProcessRunningTime(System.currentTimeMillis());
//System.out.println(&已经读取:& + pBytesRead);
UploadServlet.storeFileUploadStatusBean(this.session, fuploadStatus);
有了前面两个类的基础,下来我们可以动手去实现真正处理整个操作Servlet类。源代码如下。
package com.ncu.
import java.io.*;
import java.util.L
import javax.servlet.ServletE
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpS
import mons.fileupload.FileI
import mons.fileupload.FileUploadE
import mons.fileupload.disk.DiskFileItemF
import mons.fileupload.servlet.*;
* Servlet implementation class for Servlet: UploadServlet
public class UploadServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
public static final String UPLOAD_STATUS=&UPLOAD_STATUS&;
public static final String UPLOAD_DIR=&/upload&;
public UploadServlet() {
* 从文件路径中取出文件名
* @param filePath
private String takeOutFileName(String filePath){
int pos=filePath.lastIndexOf(File.separator);
if (pos&0){
return filePath.substring(pos+1);
return fileP
* 从request中取出FileUploadStatus Bean
* @param request
public static FileUploadStatus takeOutFileUploadStatusBean(HttpSession session){
Object obj=session.getAttribute(UPLOAD_STATUS);
if (obj!=null){
return (FileUploadStatus)
* 把FileUploadStatus Bean保存到session
* @param request
* @param uploadStatusBean
public static void storeFileUploadStatusBean(
HttpSession session,
FileUploadStatus uploadStatusBean){
session.setAttribute(UPLOAD_STATUS,uploadStatusBean);
* 删除已经上传的文件
* @param request
private void deleteUploadedFile(HttpServletRequest request){
FileUploadStatus fUploadStatus=takeOutFileUploadStatusBean(request.getSession());
for(int i=0;i&fUploadStatus.getUploadFileUrlList().size();i++){
File uploadedFile = new File(request.getRealPath(UPLOAD_DIR)+
File.separator+fUploadStatus.getUploadFileUrlList().get(i));
uploadedFile.delete();
fUploadStatus.getUploadFileUrlList().clear();
fUploadStatus.setStatus(&删除已上传的文件&);
storeFileUploadStatusBean(request.getSession(),fUploadStatus);
* 上传过程中出错处理
* @param request
* @param errMsg
* @throws IOException
* @throws ServletException
private void uploadExceptionHandle(
HttpServletRequest request,
String errMsg) throws ServletException, IOException{
//首先删除已经上传的文件
deleteUploadedFile(request);
FileUploadStatus fUploadStatus=takeOutFileUploadStatusBean(request.getSession());
fUploadStatus.setStatus(errMsg);
storeFileUploadStatusBean(request.getSession(),fUploadStatus);
* 初始化文件上传状态Bean
* @param request
private FileUploadStatus initFileUploadStatusBean(HttpServletRequest request){
FileUploadStatus fUploadStatus=new FileUploadStatus();
fUploadStatus.setStatus(&正在准备处理&);
fUploadStatus.setUploadTotalSize(request.getContentLength());
fUploadStatus.setProcessStartTime(System.currentTimeMillis());
fUploadStatus.setBaseDir(request.getContextPath()+UPLOAD_DIR);
return fUploadS
* 处理文件上传
* @param request
* @param response
* @throws IOException
* @throws ServletException
private void processFileUpload(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
DiskFileItemFactory factory = new DiskFileItemFactory();
//设置内存阀值,超过后写入临时文件
//factory.setSizeThreshold();
//设置临时文件存储位置
//factory.setRepository(new File(request.getRealPath(&/upload/temp&)));
ServletFileUpload upload = new ServletFileUpload(factory);
//设置单个文件的最大上传size
//upload.setFileSizeMax();
//设置整个request的最大size
//upload.setSizeMax();
//注册监听类
upload.setProgressListener(new UploadListener(request.getSession()));
//保存初始化后的FileUploadStatus Bean
storeFileUploadStatusBean(request.getSession(),initFileUploadStatusBean(request));
List items = upload.parseRequest(request);
//处理文件上传
for(int i=0;i&items.size();i++){
FileItem item=(FileItem)items.get(i);
//取消上传
if (takeOutFileUploadStatusBean(request.getSession()).getCancel()){
deleteUploadedFile(request);
//保存文件
else if (!item.isFormField() && item.getName().length()&0){
String fileName=takeOutFileName(item.getName());
File uploadedFile = new File(request.getRealPath(UPLOAD_DIR)+File.separator+fileName);
item.write(uploadedFile);
//更新上传文件列表
FileUploadStatus fUploadStatus=takeOutFileUploadStatusBean(request.getSession());
fUploadStatus.getUploadFileUrlList().add(fileName);
storeFileUploadStatusBean(request.getSession(),fUploadStatus);
Thread.sleep(500);
} catch (FileUploadException e) {
e.printStackTrace();
//uploadExceptionHandle(request,&上传文件时发生错误:&+e.getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
//uploadExceptionHandle(request,&保存上传文件时发生错误:&+e.getMessage());
* 回应上传状态查询
* @param request
* @param response
* @throws IOException
private void responseFileUploadStatusPoll(HttpServletRequest request,HttpServletResponse response) throws IOException{
FileUploadStatus fUploadStatus=(FileUploadStatus)request.getSession().getAttribute(UPLOAD_STATUS);
//计算上传完成的百分比
long percentComplete = (long)Math.floor(((double) fUploadStatus.getReadTotalSize()/(double) fUploadStatus.getUploadTotalSize())*100.0);
System.out.println(&com:&+percentComplete);
response.setContentType(&text/xml&);
response.setCharacterEncoding(&UTF-8&);
response.setHeader(&Cache-Control&, &no-cache&);
if ( ((long)fUploadStatus.getReadTotalSize() == (long)fUploadStatus.getUploadTotalSize()) || (fUploadStatus.getCancel() == true)){
response.getWriter().write(fUploadStatus.getStatus().toString()+&success&);
response.getWriter().write(fUploadStatus.getStatus().toString()+&&div class=\&prog-border\&&&div class=\&prog-bar\& style=\&width: &
+ percentComplete + &%;\&&&/div&&/div&&);
* 处理取消文件上传
* @param request
* @param response
* @throws IOException
private void processCancelFileUpload(HttpServletRequest request,HttpServletResponse response) throws IOException{
FileUploadStatus fUploadStatus=(FileUploadStatus)request.getSession().getAttribute(UPLOAD_STATUS);
fUploadStatus.setCancel(true);
request.getSession().setAttribute(UPLOAD_STATUS, fUploadStatus);
responseFileUploadStatusPoll(request,response);
* 在上传文件列表中查找与文件名相关的id
* @param request
* @param fileName 文件名
* @return 找到返回id,否则返回-1
private int findFileIdInFileUploadedList(HttpServletRequest request,String fileName){
FileUploadStatus fileUploadStatus=takeOutFileUploadStatusBean(request.getSession());
for(int i=0;i&fileUploadStatus.getUploadFileUrlList().size();i++){
if (fileName.equals((String)fileUploadStatus.getUploadFileUrlList().get(i))){
return -1;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
processFileUpload(request,response);
request.setCharacterEncoding(&UTF-8&);
if (request.getParameter(&uploadStatus&)!=null){
responseFileUploadStatusPoll(request,response);
if (request.getParameter(&cancelUpload&)!=null){
processCancelFileUpload(request,response);
至此,服务器端的代码已经基本完成。
5.&客户端实现
由于在上传文件时需要在同一页面显示对应的进度条控件,因此,在提交表单时当前页面不能被刷新。我们可以通过将表单提交至一个隐藏的&iframe&中来实现。关于Ajax的技术前面讲过,这里就不再细说,直接给出源代码如下:
&!DOCTYPE html PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&Content-Type& content=&text/ charset=UTF-8&&
&title&基于Ajax的上传文件显示进度条&/title&
.prog-border {
height: 15
width: 205
background: #
border: 1px solid #000;
margin: 0;
padding: 0;
.prog-bar {
height: 11
padding: 0
background: #178399;
font-size: 10
font-family: Arial, Helvetica, sans-
font-size: 10
&script language=&javascript& type=&text/javascript&&
//var userName=document.getElementById(&userName&).
//创建跨浏览器的XMLHttpRequest对象
function startListener(){
xmlhttp = new ActiveXObject('Msxm12.XMLHTTP');
}catch(e){
//IE 5.5 及更高版本
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
//其他浏览器
xmlhttp = new XMLHttpRequest();
}catch(e){}
var progressStatusText = document.getElementById(&progressBar&);
xmlhttp.open(&get&,&UploadServlet?uploadStatus=true&,true);
/**此处Header设置非常重要,必须设置Content-type类型,负责会报错误
xmlhttp.setRequestHeader(&Content-type&, &application/x-www-form-urlencoded&);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
progressStatusText.innerHTML = &&;
progressStatusText.innerHTML = xmlhttp.responseT
var temp = xmlhttp.responseText.indexOf(&success&);
temp & 0 ){
window.clearTimeout(timer);
timer = window.setTimeout(startListener,1000);
xmlhttp.send(null);
function startUpload(){
timer = window.setTimeout(startListener,1000);
function cancelUpload(){
xmlhttp = new ActiveXObject('Msxm12.XMLHTTP');
}catch(e){
//IE 5.5 及更高版本
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
//其他浏览器
xmlhttp = new XMLHttpRequest();
}catch(e){}
var progressStatusText = document.getElementById(&progressBar&);
xmlhttp.open(&get&,&UploadServlet?cancelUpload=true&,true);
xmlhttp.setRequestHeader(&Content-type&, &application/x-www-form-urlencoded&);
//xmlhttp.setRequestHeader(&Content-type&, &multipart/form-data&);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
progressStatusText.innerHTML = &&;
progressStatusText.innerHTML = xmlhttp.responseT
xmlhttp.send(null);
&div id=&controlPanel&&
&!-- 这个是隐藏的&iframe&作为表单提交后处理的后台目标
通过表单form的target属性指定该&iframe&将返回信息显示在&iframe&框架中
&iframe id='target_upload' name='target_upload' src='' style='display: none'&&/iframe&
&form id=&fileUploadForm& name=&fileUploadForm& action=&UploadServlet&
enctype=&multipart/form-data& method=&post& onsubmit=&return startUpload();& target=&target_upload&&
&input type=&file& name=&file& id=&file& size=&40&/&&br&
&input type=&submit& name=&uploadButton& id=&uploadButton& value=&开始上传&/&
&input type=&button& name=&cancelUploadButton& id=&cancelUploadButton& value=&取消上传& onclick=&return cancelUpload();&/&&br&
&div id=&progressBar&&
&至此,整个文件上传的实现到此完成,读者可以在此基础上,发挥自己的创新能力,去完善此实例。
Good Luck!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:87973次
排名:千里之外
转载:29篇
评论:22条
(3)(18)(1)(2)(6)(2)}

我要回帖

更多关于 100m服务器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信