当前位置:编程学习 > C#/ASP.NET >>

.net上传图片的问题

各位高手,我现在碰到了一个奇怪的问题。就是我的一个网站源文件在我自己电脑上运行,用FileUpload上传图片都没问题,但是放到我们的服务器上,就报错。就说什么路径有问题。我明明路径弄的都是一样的。不知道是不是我服务器上漏了什么文件,导致那个上传图片控件出错,请大家帮我看看?实在是没办法了 --------------------编程问答-------------------- 求易做图 贴图 贴码 --------------------编程问答--------------------   public string UploadPicFile(FileUpload FileUp)
    {
        string filefullname = FileUp.PostedFile.FileName;
        string filename = filefullname.Substring(filefullname.LastIndexOf("\\") + 1);
        string type = filename.Substring(filename.LastIndexOf(".") + 1);
        string imgurl = "";
        if ( type == "jpg" || type == "gif" || type == "JPG" || type == "png" || type == "GIF"|| type == "PNG")
        {
            try
            {
                if (FileUp.HasFile)
                {
                    if ((FileUp.PostedFile.ContentLength) / 1024 > 3072)
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('上传图片大小不能超过3M');", true);
                        return string.Empty;
                    }
                    else
                    {
                        FileUp.PostedFile.SaveAs(this.Server.MapPath("~/webadmin/product/images") + "\\" + filename);
                        imgurl = "~/webadmin/product/images" + "/" + filename;
                        return imgurl;
                    }
                }
                else
                {
                    return string.Empty;
                }
               
            }
            catch(Exception ex)
            {
                //throw ex;
               ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('上传图片错误,请检查路径!');", true);
                return string.Empty;
            }
        }
        else
        {
            //Lable_msg.Text = "图片格式应为bmp,jpg,gif";
            return string.Empty;
        }
    }

这个就是我写的上传图片的方法 --------------------编程问答--------------------
引用 1 楼  的回复:
求易做图 贴图 贴码

en --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答--------------------             if (this.FileUpload.FileName == "")
            {
                Response.Write("<script>alert('请选择上传文件!');history.go(-1); </script>");
                return;
            }
            if (this.FileUpload.PostedFile.ContentType.ToLower().IndexOf("image") >= 0)
            {
                string info_pic = System.Guid.NewGuid().ToString("D") + System.IO.Path.GetExtension(this.FileUpload.FileName);
                this.FileUpload.SaveAs(Server.MapPath("../../upfile/" + info_pic));
                if (db.db_banner_ADD(webguid, int.Parse(_target), _url, int.Parse(_px), info_pic) == 1)
                {
                    Response.Write("<script>alert('添加成功!');window.location.href='compic.aspx';</script>");
                    return;
                }
                else
                {
                    if (System.IO.File.Exists(Server.MapPath("../../upfile/" + info_pic)))
                    {
                        System.IO.File.Delete(Server.MapPath("../../upfile/" + info_pic));
                    }

                    Response.Write("<script>alert('数据写入失败,请重试!');window.location.href='compic.aspx';</script>");
                    return;
                }
            }
            else
            {
                Response.Write("<script>alert('文件类型必须为图片类型!');history.go(-1); </script>");
                return;
            } --------------------编程问答-------------------- 打印一下 捕获异常 ex 的错误消息,看看
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,