一.前台页面代码:
二.后台处方法: (本方法写在了页面上)
HttpFileCollection files = this.Request.Files; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { System.IO.Stream stream = files[i].InputStream; string fileFullName = files[i].FileName; int index = fileFullName.LastIndexOf("\\"); string fileName = fileFullName.Substring(index + 1); //得到指定上传文件的字节输入流 int imgDataLen = (int)(stream.Length); byte[] imgData = new byte[imgDataLen]; int n = stream.Read(imgData, 0, imgDataLen); stream.Close(); System.IO.FileStream myFileStream = new System.IO.FileStream(Server.MapPath(fileName), System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write); myFileStream.Write(imgData, 0, imgDataLen); myFileStream.Flush(); myFileStream.Close(); } } %>