上传图片

来源:互联网 发布:阿里云 搭建ss 编辑:程序博客网 时间:2024/05/30 04:39
 

 protected void btn_up_Click(object sender, EventArgs e)
    {
        if (fup.HasFile && fup.Site < 10)
        {
            string path = Server.MapPath("~/Upload/");
            string filest = Path.GetExtension(fup.FileName).ToLower();
            string[] allowedestion = { ".gif", ".jpg", ".jpeg", "png" };
            bool tf = false;
            for (int i = 0; i < allowedestion.Length; i++)
            {
                if (filest == allowedestion[0])
                {
                    tf = true;
                }
            }
            if (tf)
            {

                try
                {
                    fup.PostedFile.SaveAs(path + fup.FileName);
                    Response.Write("上传成功");
                }
                catch (Exception ex)
                {
                    Response.Write("上传失败");
                }
            }
            else
            {
                Response.Write("<script>alert('不支持改格式文件上传');</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('文件过大');</script>");
        }
    }