• 图片上传类


      调用: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 "";
                }
            }

  • 相关阅读:
    CUDA中修饰符的解释
    [C] zintrin.h : 智能引入intrinsic函数。支持VC、GCC,兼容Windows、Linux、Mac OS X
    GPU优化方法[转]
    Angularjs实例2
    Angularjs实例1
    Services 在多个 controller 中共享数据。
    自定义AngularJS中的services服务
    AngularJS web应用程序
    AngularJS 表单
    在文件中的AngularJS模块
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/2055934.html
Copyright © 2020-2023  润新知