注册 登录
编程论坛 ASP.NET技术论坛

上传图片时提示:类型出错

ycbbg 发布于 2008-08-16 10:03, 652 次点击
上传图片时提示:类型出错,但我选择的是其中的类型呀

protected void Button1_Click(object sender, EventArgs e)
    {
        UP_img up_img = new UP_img();
        if (FileUpload1.HasFile)
        {
            string fileContentType = FileUpload1.PostedFile.ContentType;
            if (fileContentType == "bmp" || fileContentType == "gif" || fileContentType == "jpg")
            {
                string name = FileUpload1.PostedFile.FileName;                         // 客户端文件路径
                FileInfo file = new FileInfo(name);
                string fileName = file.Name;                                           // 文件名称
                //string fileName_s = "x_" + file.Name;                                  // 缩略图文件名称
                //string fileName_sy = "text_" + file.Name;                              // 水印图文件名称(文字)
                //string fileName_syp = "w_" + file.Name;                            // 水印图文件名称(图片)
                string webFilePath = Server.MapPath("ImgUpload")+"/" + fileName;          // 服务器端文件路径
                string webFilePath_s = Server.MapPath("ImgUpload")+"/S_" + fileName;    // 服务器端缩略图路径
                //string webFilePath_sy = Server.MapPath("ImgUpload/" + fileName_sy);   // 服务器端带水印图路径(文字)
                string webFilePath_syp = Server.MapPath("ImgUpload")+"/W_" + fileName; // 服务器端带水印图路径(图片)
                string webFilePath_sypf = Server.MapPath("ImgUpload")+"/water.png";                // 服务器端水印图路径(图片)
                try
                {
                    FileUpload1.SaveAs(webFilePath);                                   // 使用 SaveAs 方法保存文件
                    //AddWater(webFilePath, webFilePath_sy);
                    up_img.AddWaterPic(webFilePath, webFilePath_syp, webFilePath_sypf);
                    up_img.MakeThumbnail(webFilePath, webFilePath_s, 130, 130, "W");          // 生成缩略图方法
                    Response.Write("文件上传成功!");
                    TextBox_img.Text = fileName;
                    (webFilePath);
                }
                catch (Exception ex)
                {
                    Response.Write("文件上传失败!");
                }
            }
            else
            {
                Response.Write("文件类型不符!");
            }
        }
    }
1 回复
#2
keepfire2008-08-16 11:00
你试试将你定义的fileContentType的值显示出来看看
1