• 上传图片的方法以及判断


    <asp:FileUpload ID="fulImage" runat="server" Width="346px" /><br />
    <asp:Image ID="imgPro" runat="server" Width="118px" Height="88"/><font color="red">(图片大小:300*226px)</font>
    <asp:Button ID="btnUpImg" AccessKey="1" runat="server" Text="上传图片" onclick="btnUpImg_Click" Width="96px" Height="30px" />

    if (imgPro.ImageUrl.Substring(imgPro.ImageUrl.LastIndexOf("/") + 1).Equals("productDemo.gif"))
    strErr.Append("请上传图片!");
    string proimg = imgPro.ImageUrl;

    protected void btnUpImg_Click(object sender, EventArgs e)
        {
            string picName = "";
            string file = "/images/small/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "-" + DateTime.Now.Day + "/";
            SetFocus("btnSubmit");
            UploadPicture.CreatDirectory(file);
            txtName.Text = fulImage.FileName.Replace(".gif", "").Replace(".jpg", "");
            if (fulImage.FileName != null && fulImage.FileName != "")
            {
                picName = UploadPicture.UploadInfo(fulImage, file);
    
                if (picName == null)
                    Response.Write("<script>alert('图片上传失败!')</script>");
                else
                    imgPro.ImageUrl = UploadPicture.formatPics(picName);
            }
        }
    
    
    
    
    
    public static string UploadInfo(FileUpload fu, string file)
        {
            Random myRd = new Random();
    
            string prefix = System.IO.Path.GetExtension(fu.FileName).ToLower();
            string fileName = "";
            if (prefix.Equals(".jpg") || prefix.Equals(".gif") || prefix.Equals(".jpeg"))
            {
                string strFileName = DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", "") + myRd.Next(1000) + prefix;
                string name = System.Web.HttpContext.Current.Server.MapPath(file + strFileName);
                fileName = file + strFileName;
                fu.SaveAs(name);
                return fileName;
            }
            else
                return null;
        }
    

      

  • 相关阅读:
    数据表格优化
    vue数组和对象的监听变化
    python flask框架搭建以及大佬代码参考
    简单爬虫
    srs的基本配置
    记录飞天程序库调用
    面试题 递归算法1+2+....+100求和
    下载列表组件
    Prometheus之系统安装,启动
    nginx之日志
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4713552.html
Copyright © 2020-2023  润新知