这是后台代码:其中会有一个上传图片的功能,在本地调试和挂到服务器那边调试都会显示你上传的不是JPG图片,但是我上传的就是JPG图片啊,都知道什么地方错了,郁闷死了,请大家帮忙看一下
 private void AddUser(int CostTypeId )
    {
         if ((FileAttach.PostedFile.FileName != null) && (FileAttach.PostedFile.ContentLength > 0))
        {
            string Attachaddress;
            Attachaddress = "~/Attach/";
            string filename;
            filename = FileAttach.PostedFile.FileName.ToString();
            filename = filename.Substring(filename.LastIndexOf("\\") + 1);
            string imgurl;
            imgurl = Server.MapPath(Attachaddress) + filename;
            FileAttach.PostedFile.SaveAs(imgurl);
            ViewState["Attachurl"] = filename;
         
           
        }
      
        SqlParameter[] parms = new SqlParameter[24];        parms[0] = new SqlParameter("@NTID",SqlDbType.VarChar,50);
        parms[0].Direction = ParameterDirection.Input;
        parms[0].Value=TxtNTID.Text;
                    parms[1] = new SqlParameter("@EmplyeeNumber",SqlDbType.VarChar,50);
        parms[1].Direction = ParameterDirection.Input;
        parms[1].Value =TxtEmplyeeId.Text;        parms[2] = new SqlParameter("@MobilityUserFirstName",SqlDbType.VarChar,50);
        parms[2].Direction = ParameterDirection.Input;
        parms[2].Value =TxtFirstName.Text;        parms[3] = new SqlParameter("@MobilityUserlastName",SqlDbType.VarChar,50);
        parms[3].Direction = ParameterDirection.Input;
        parms[3].Value =TxtLastName.Text;        parms[4] = new SqlParameter("@MobilityUserChineseName",SqlDbType.VarChar,50);
        parms[4].Direction = ParameterDirection.Input;
        parms[4].Value =TxtCName.Text;        parms[5] = new SqlParameter("@Mail",SqlDbType.VarChar,50);
        parms[5].Direction = ParameterDirection.Input;
        parms[5].Value =TxtEmail.Text;        parms[6] = new SqlParameter("@ManagerName",SqlDbType.VarChar,50);
        parms[6].Direction = ParameterDirection.Input;
        parms[6].Value =TxtManagerName.Text;        parms[7] = new SqlParameter("@ManagerMail",SqlDbType.VarChar,50);
        parms[7].Direction = ParameterDirection.Input;
        parms[7].Value =TxtManegerEmail.Text;
        
        parms[8] = new SqlParameter("@IdentityCard",SqlDbType.VarChar,50);
        parms[8].Direction = ParameterDirection.Input;
        parms[8].Value =TxtTWPC.Text;        parms[9] = new SqlParameter("@PostId",SqlDbType.Int);
        parms[9].Direction = ParameterDirection.Input;
        parms[9].Value =Convert.ToInt32(DPPost.SelectedValue.ToString());        parms[10] = new SqlParameter("@HRJobTitleId",SqlDbType.Int);
        parms[10].Direction = ParameterDirection.Input;
        parms[10].Value =Convert.ToInt32(DPHRJobTitle.SelectedValue.ToString());        parms[11] = new SqlParameter("@PostTitleId",SqlDbType.Int);
        parms[11].Direction = ParameterDirection.Input;
        parms[11].Value =Convert.ToInt32(DPPostTitle.SelectedValue.ToString());        parms[12] = new SqlParameter("@CostCenterId",SqlDbType.Int);
        parms[12].Direction = ParameterDirection.Input;
        parms[12].Value =Convert.ToInt32(DPCostCenter.SelectedValue.ToString());        parms[13] = new SqlParameter("@AttachInfo",SqlDbType.VarChar,50);
        parms[13].Direction = ParameterDirection.Input;
        parms[13].Value =ViewState["Attachurl"];        parms[14] = new SqlParameter("@Res",SqlDbType.VarChar,200);
        parms[14].Direction = ParameterDirection.Input;
        parms[14].Value =TextBox1.Text;        parms[15] = new SqlParameter("@SRNumber",SqlDbType.VarChar,50);
        parms[15].Direction = ParameterDirection.Input;
        parms[15].Value =TxtSRId.Text;;        parms[16] = new SqlParameter("@DepartmentId",SqlDbType.Int);
        parms[16].Direction = ParameterDirection.Input;
        parms[16].Value =Convert.ToInt32(DPDepartment.SelectedValue.ToString());        parms[17] = new SqlParameter("@FactoryId",SqlDbType.Int);
        parms[17].Direction = ParameterDirection.Input;
        parms[17].Value =Convert.ToInt32(DPFactory.SelectedValue.ToString());        parms[18] = new SqlParameter("@ApplyTypeName",SqlDbType.VarChar,50);
        parms[18].Value =DPApplyType.SelectedValue.ToString();        parms[19] = new SqlParameter("@MTUsingTypeName",SqlDbType.VarChar,50);
        parms[19].Direction = ParameterDirection.Input;
        parms[19].Value =DropDownList3.SelectedValue.ToString();        parms[20] = new SqlParameter("@PCUsingTypeNAme",SqlDbType.VarChar,50);
        parms[20].Direction = ParameterDirection.Input;
        parms[20].Value = DPPCUsingType.SelectedValue.ToString();        parms[21] = new SqlParameter("@CostTypeId",SqlDbType.Int);
        parms[21].Direction = ParameterDirection.Input;
        parms[21].Value =CostTypeId;        parms[22] = new SqlParameter("@PCTypeId",SqlDbType.Int);
        parms[22].Direction = ParameterDirection.Input;
        parms[22].Value =Convert.ToInt32(DropDownList1.SelectedValue.ToString());        parms[23] = new SqlParameter("@returns",SqlDbType.Int);
        parms[23].Direction = ParameterDirection.Output;        ExecPro.ExecPro.ExecuteNonQuery(conn, CommandType.StoredProcedure, "AddUser", parms);
        //--------------以下是输出参数------------------
       
       int returns =Convert.ToInt32(parms[23].Value.ToString());
            if(returns==1)
            {
                Response.Write("<script language=javascript>alert('此員工信息已經存在!'); window.location='ApplyIndex.aspx';</script>");
            }
                
            if (returns == 0)
          
           {
                ExecPro.ExecPro.ExecuteNonQuery(conn, CommandType.StoredProcedure, "AddUser", parms);
                Response.Write("<script language=javascript>alert('操作成功!');</script>");
                Response.Write("<script language=javascript>this.window.opener = null;window.close();</script>");
                SendSMTPMail("huamsg12", "[email protected]", "", TxtEmail.Text, "MobileManagementSystem", "您已成功提交了線上手機申請,此郵件系統自動發出,請勿回复!");
                //SendSMTPMail("huamsg12", "[email protected]", "", "[email protected]", "MobileManagementSystem", "已有線上手機申請,請您批准,此郵件系統自動發出,請勿回复!");
            }
                
                   
       
    }
    protected void ButSubmit_Click(object sender, EventArgs e)
    {
        if (DPApplyType.SelectedItem.Text == "請選擇")
        { 
            Response.Write("<script language=javascript>alert('請選擇申請類型');</script>");
        }
       
        if (FileAttach.PostedFile.ContentType !=".jpg")
        {
            Response.Write("<script language=javascript>alert('请上传JPG图片!'); </script>");
        }
        else
        {
            if (DPApplyType.SelectedItem.Text == "申請手機卡")
            {
                AddUser(Convert.ToInt32(DropDownList2.SelectedValue.ToString()));
            }
            if (DPApplyType.SelectedItem.Text == "申請手機和手機卡")
            {
                AddUser(Convert.ToInt32(DropDownList4.SelectedValue.ToString()));
            }
        }
    }请大家帮我看一下,到底哪里是不对的谢谢大家了

解决方案 »

  1.   

    JPG 和jpg  是不同的  要除大小写
      

  2.   


    <form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
     <p><input type="hidden" name="MAX_FILE_SIZE" value="100000" /></p>
     <p><input name="userfile" id="userfile" type="file"/></p>
     <p><input type="button" name="button_1" value="按钮" onclick="return check();" /></p>
    </form><script language="javascript" type="text/javascript">
      function check()
        {
        var aa=document.form1.userfile.value.toLowerCase().split('.');//以“.”分隔上传文件字符串
            alert(aa)
        if(document.form1.userfile.value=="")
        {
            alert('图片不能为空!');
            return true;
        }
        else
        {
        if(aa[aa.length-1]=='gif'||aa[aa.length-1]=='jpg'||aa[aa.length-1]=='bmp')//判断图片格式
        {
            alert('图片格式正确!');
            return true;
        }
        else
        {
            alert('对不起,你选择的图片格式不对\n图片格式应为*.jpg、*.gif、*.bmp');
            return false;
        }
        }
        }
      </script>
      

  3.   

    断点调试一下看看FileAttach.PostedFile.ContentType是什么
    if (FileAttach.PostedFile.ContentType !=".jpg")
      

  4.   

    我用的服務器端控件,fileupload 控件,好像JS不能用,我在看看
      

  5.   

    .jpg
    改成.JPG大小写要注意
      

  6.   

    FileAttach.PostedFile.ContentType返回的是:image/jpeg
    if (FileAttach.PostedFile.ContentType !="image/jpeg")
      

  7.   

    打断点看if (FileAttach.PostedFile.ContentType 这个值是多少。。
      

  8.   


    傳出來的值怎麼會是這個呢?“image/pjepg”
      

  9.   

    傳出來的值怎麼會是這個呢?“image/pjepg”  ,這是什麼?
      

  10.   

    你就取点后面的字符,  进行判断吧.   别取ContentType 了.  
      

  11.   

    查看
    http://baike.baidu.com/view/160611.htm
      

  12.   

        取后缀名? 你新建一个txt  然后改下后缀名成 jpg
       你取后缀名判断也还行?