| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 638 人关注过本帖
标题:上传图片时提示:类型出错
只看楼主 加入收藏
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
结帖率:100%
收藏
 问题点数:0 回复次数:1 
上传图片时提示:类型出错
上传图片时提示:类型出错,但我选择的是其中的类型呀

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("文件类型不符!");
            }
        }
    }
搜索更多相关主题的帖子: 类型 提示 
2008-08-16 10:03
keepfire
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-6-10
收藏
得分:0 
你试试将你定义的fileContentType的值显示出来看看
2008-08-16 11:00
快速回复:上传图片时提示:类型出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017947 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved