开始以为会很麻烦,需要什么读二进制流写二进制流的,结果自己试了一下,还真简单。。直接一个saveAs就行了。。。
下面是HTML代码:

 

 

代码
  <form id="form2" action="Handle/Upload.ashx" method="post" enctype="multipart/form-data" >
    
<input type="file" id="imgFileName" name="imgName" style="width:220px;" />
    
<input type="submit" value="上传" />
    
</form>

 

 

在这里我是用了一般处理程序来进行文件的上传,代码如下:

 

代码
<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;

public class Upload : IHttpHandler {
    
    
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType 
= "text/plain";
        HttpPostedFile imgFile 
= context.Request.Files["imgName"];
        String fileName
=imgFile.FileName;
        fileName 
= fileName.Substring(fileName.LastIndexOf("\\")+1);
        String savePath 
= context.Server.MapPath("../Upload/"+ fileName;
        imgFile.SaveAs(savePath);
        context.Response.Write(
"<br>保存成功!文件名:" + fileName);   
    }
 
    
public bool IsReusable {
        
get {
            
return false;
        }
    }

}

 

 

相关文章:

  • 2021-06-17
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-11
  • 2021-10-01
  • 2021-11-16
  • 2021-08-01
  • 2021-06-01
相关资源
相似解决方案