| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 222 人关注过本帖
标题:上传图片时提示:类型出错
收藏  订阅  推荐  打印 
ycbbg
Rank: 2
来自:江西
等级:注册会员
帖子:73
积分:926
注册:2007-11-26
上传图片时提示:类型出错

上传图片时提示:类型出错,但我选择的是其中的类型呀

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;
                    System.IO.File.Delete(webFilePath);
                }
                catch (Exception ex)
                {
                    Response.Write("文件上传失败!");
                }
            }
            else
            {
                Response.Write("文件类型不符!");
            }
        }
    }
搜索更多相关主题的帖子: 类型  提示  
2008-8-16 10:03
keepfire
Rank: 1
等级:新手上路
帖子:8
积分:182
注册:2008-6-10

你试试将你定义的fileContentType的值显示出来看看
2008-8-16 11:00
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.047726 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved