<input type="file" id="headlogo" >来上传图片  在得到服务器路径后  进行保存图片时PostFile值为空 。 怎么回事?  急求解决方案

解决方案 »

  1.   

    上传二进制
    if (FileUpLogo.HasFile)
    {
      //取得上传文件的大小
      int FileLen = FileUpLogo.PostedFile.ContentLength;
      Byte[] FileData = new Byte[FileLen];
      //创建访问客户端上传文件的对象
      HttpPostedFile hp = FileUpLogo.PostedFile;
      //创建数据流对象
      System.IO.Stream sr = hp.InputStream;
      //将图片数据放到FileData数组对象实例中,0代表数组指针的起始位置,FileLen代表指针的结束位置
      sr.Read(FileData, 0, FileLen);
      //将FileData 赋值给实体
      brandModel.fld_logo = FileData;
    }
      

  2.   

    <input type="file" id="headlogo" >
    不是服务端控件?
      

  3.   

    你是用Ajax上传的???
    如果不是,你的<input type="file"  runat ="server" id="headlogo" >后台才可以获取里值的
      

  4.   

    前台:
       <input type="file" name="headlogo"   id="headlogo" runat="server" style=" height:26px; width:300px"/>
      <input type="hidden" name="headlogodef" id="headlogodef" runat="server" value="<%=image()%>logo.gif" />
    后台:
     private void updateValue()
            {
                Random ran = new Random();
                Maticsoft.Model.Category cate = new Maticsoft.Model.Category();
                cate.Id = int.Parse(cid);
                //获取上传值
              string headLogo=Request.Form["headlogo"];
                          #region MyRegion上传图片
              string[] exts = { "jpg", "gif", "jpeg", "bmp", "png" };
                string createUpload = "~/upfile/image/";
                if (headLogo != "")             {
                    #region 上传headlogo图片
                    //判断上传文件的大小
                    string contentType = headlogo.PostedFile.ContentType.ToLower();
                    if (headlogo.MaxLength> 512000)
                    {
                        Console.Write("请上传 512KB 以内的图片");
                        return;
                    }
                    string uploadName = headLogo;
                   string hpictureName = "";
                    if (headLogo != "") //(headlogo.FileName != "")   
                    { 
                        int idx = uploadName.LastIndexOf(".");
                        string suffix = uploadName.Substring(idx);//获得上传的图片的后缀名                     if (suffix.ToLower() == ".jpg" || suffix.ToLower() == ".png" || suffix.ToLower() == ".gif" || suffix.ToLower() == ".jpeg" || suffix.ToLower() == ".bmp")
                        {
                            hpictureName = DateTime.Now.Ticks.ToString() + ran.Next() + suffix;
                            
                        }
                        else
                        {
                            //SetError("图片格式不正确!");
                            Response.Redirect("~/webpage/ajaxPage/TypeProject.aspx");
                            Response.End();
                            return;
                        }
                        
                    }
                    if (uploadName != "")
                    {
                        string path = Server.MapPath(createUpload);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);                    }
                     headlogo.PostedFile.SaveAs( path + hpictureName);
                    }
                    string url = createUpload + hpictureName;
                    cate.Image = url;
                           }
                #endregion
                category.updateProjectIamge(cate);
            }在保存图片时    headlogo.PostedFile.SaveAs( path + hpictureName);
    中的PostFile值为null
      

  5.   

     <input type="file" name="headlogo" id="headlogo" runat="server" style=" height:26px; width:300px"/>
      对于微软的上传  必须postback 才会获取到值滴   一旦用到无刷新 就要控制好 
      

  6.   

    对于上传文件的格式验证, 建议你js/jq做
    <input id="fileup" typ="file" runat="server" onchang="js格式验证">
      

  7.   

    验证什么的 现在将 headlogo.PostedFile.SaveAs( path + hpictureName);注释的话,
    数据库可以获取到正确的路径/upfile/image/6344027521701562501406568014.jpg
    但是图片没有保存到该位置中。   
    先知道怎么解决保存图片这个 和 验证有很大的关联吗?