zoukankan      html  css  js  c++  java
  • 图片上传类

      调用:UpLoadIMG(this.FileName, "/upload/pic/", ".GIF.JPG.PNG.SWF");

    public static string TransToTwo(string theStr)
            {
                if (theStr.Length == 1)
                {
                    return "0"+theStr;
                }
                else
                {
                    return theStr;
                }
            }
           
            public static string UpLoadIMG(FileUpload fulFile, string DirectionName,string ExtName)
            {
                try
                {
                    //string FileName = fulFile.FileName;
                    string returnStr = "";

                    string FileSavePath = System.Web.HttpContext.Current.Server.MapPath("~/"); //获取文件存放的根路径

                    if (fulFile.HasFile) //判断是否选择了要上传的文件
                    {
                        string name = fulFile.PostedFile.FileName;

                        string DirectionName2 = DateTime.Now.Year.ToString() + TransToTwo(DateTime.Now.Month.ToString());

                        string DirectionName3 = TransToTwo(DateTime.Now.Day.ToString()) + TransToTwo(DateTime.Now.Hour.ToString()) + TransToTwo(DateTime.Now.Minute.ToString()) + TransToTwo(DateTime.Now.Second.ToString()) + DateTime.Now.Millisecond.ToString();

                        FileInfo file = new FileInfo(name);

                        string CreatePath="";
                        CreatePath =FileSavePath + DirectionName + DirectionName2 ;
                        FileSavePath += DirectionName + DirectionName2 +"/"+DirectionName3+ file.Extension;

                        if (ExtName.Contains( file.Extension.ToUpper() )) //符合类型
                        {
                            try
                            {
                                try
                                {
                                    if (!Directory.Exists(CreatePath))
                                    {
                                        Directory.CreateDirectory(CreatePath);
                                    }
                                }
                                catch
                                {
                                    throw;
                                }
                                fulFile.SaveAs(FileSavePath);
                            }
                            catch (Exception Error)
                            {
                                HttpContext.Current.Response.Write(" <script>alert('" + Error.Message + "') </script>");
                                return "";
                            }
                            returnStr = DirectionName2 + "/" + DirectionName3;
                      }
                        else
                        {
                            HttpContext.Current.Response.Write(" <script>alert('该文件格式不正确!') </script>");
                            return "";
                        }
                    }
                    else
                    {
                        return "";
                    }
                }
                catch
                {
                    return "";
                }
            }

  • 相关阅读:
    编码转换,基础补充,深浅拷贝,id is == ,代码块(了解),小数据池(了解)
    字典(dict),字典的嵌套,集合(set)
    列表,列表的增删改查,列表的嵌套,range
    整数,布尔值,字符串,字符串详解.
    [小明学Shader]4.自定义光照----RampTexture
    [小明学Shader]3.自定义光照,半拉姆伯特
    [小明学Shader]2.理解Shader和Material的关系
    [小明学Shader]1.Diffuse
    [UGUI]你说UnityEngine.UI.Button是怎么通过拖动来增加OnClick的监听器的呢?
    [小明也得懂架构]1.架构初探
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/2055934.html
Copyright © 2011-2022 走看看