头像上传的过程!~

时间:2022-09-03 20:07:59
  private string strGetFace
  {
   get
   {   
    string strResult="";
    
 
    if(FaceUpload.PostedFile.ContentLength > 0)
    {
     //设定上传文件的保存路径
     string strSaveDir = "./face/";
     string strName = FaceUpload.PostedFile.FileName;
     //取得文件名(抱括路径)里最后一个"."的索引
     int intExt = strName.LastIndexOf(".");
     
     //取得文件扩展名
     string strExt = strName.Substring(intExt);
     
     //这里自动根据日期和文件大小不同为文件命名,确保文件名不重复
     DateTime datNow = DateTime.Now;
     string strNewName = datNow.DayOfYear.ToString() + FaceUpload.PostedFile.ContentLength.ToString() + strExt;
     
     string intPath = strSaveDir+strNewName;
     
                    //上传文件的类型
     
     if (strExt == ".jpg" || strExt == ".gif")
     {
      //保存文件到你所要的目录,这里是IIS根目录下的upload目录.你可以改变.
      //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"/"必须用"//"代替
      FaceUpload.PostedFile.SaveAs(Server.MapPath(strSaveDir + strNewName));
      strResult=intPath;
     }
     else
     {
                        Response.Redirect("?out=error&id=601");
     }
    }
    else
    {
     if (FaceUrl.Text.ToString() != "" && FaceUrl.Text.ToString() != null)
      strResult = FaceUrl.Text.ToString().Trim();
     else
      strResult = "face/"+Request.Form["Faces"].ToString().Trim();
    }
    return strResult;
    
   }
  }