ASP.net 上传

 if (FileUpload1.HasFile) 
        {
            string filename = FileUpload1.PostedFile.FileName;
            string dir_file = "images/";
            string ab_path = Server.MapPath(dir_file);
            int pos = filename.LastIndexOf(".");
            string pirefix = filename.Substring(pos);
            if (pirefix != ".jpg")
            {
                Response.Write("<script>alert('文件格式不正确');</script>");
            }
            else
            {
                if (!Directory.Exists(ab_path))
                {
                    Directory.CreateDirectory(ab_path);
                }
                //格式


                string daname = DateTime.Now.Ticks.ToString() + pirefix; //文件名防重复



                FileUpload1.SaveAs(ab_path + daname);
                Response.Write("<script>alert('文件上传成功');</script>");
            }
        }

  

posted @ 2016-10-20 14:48  尘梦  阅读(131)  评论(0编辑  收藏  举报