zoukankan      html  css  js  c++  java
  • 如何实现文件的上传

         在asp.net中有一个HtmlInputFile HTML控件,该控件可以用来在客户端选择要上传的文件,并把文件上传   到服务器端.  

      方法一 

         string sFileName = Path.GetFileName(this.File1.PostedFile.FileName);//获取文件名
            string sFilePath = Server.MapPath("./Image/" + sFileName);//MapPath方法,把客户端的文件上传到服务器上指定的文件夹下.
            this.File1.PostedFile.SaveAs(sFilePath);

     方法二

    上传文件的同时获取文件的后缀名

                string TrueName = "";
                string RandomName = "";
                int ii;
                #region 上传图片
                string RandomString = Convert.ToString(Guid.NewGuid());
                TrueName = Path.GetFileName(ImageFile.PostedFile.FileName);
                ii = TrueName.LastIndexOf(".");
                if (ii != -1)
                {
                    string ExtendName = TrueName.Substring(ii);
                    RandomName = RandomString + ExtendName;
                    string filepath = Server.MapPath("~/Images/Photo/" + RandomName);
                    if (ExtendName != ".jpg" && ExtendName != ".gif" && ExtendName != ".bmp" &&  ExtendName != ".JPG" && ExtendName != ".GIF" && ExtendName != ".BMP")
                    {
                        Response.Write("<script language=\"javascript\">alert('只能上传jpg,gif,bmp格式的图片!');</script>");
                        return;
                    }
                    if (ImageFile.PostedFile.ContentLength > 202800)
                    {
                        Response.Write("<script language=\"javascript\">alert('上传图片不能超过200k!');</script>");
                        return;
                    }
                    else
                    {
                        ImageFile.PostedFile.SaveAs(filepath);
                    }
                }
                #endregion

  • 相关阅读:
    反向代理实例
    nginx常用命令和配置
    nginx的安装
    Can Live View boot up images acquired from 64bit OS evidence?
    What is the behavior of lnk files?
    EnCase v7 search hits in compound files?
    How to search compound files
    iOS 8.3 JB ready
    Sunglasses
    现代福尔摩斯
  • 原文地址:https://www.cnblogs.com/zhc088/p/677470.html
Copyright © 2011-2022 走看看