zoukankan      html  css  js  c++  java
  • 在ASP.NET中实现图片、视频文件上传方式

    一、图片

    1、在前端用<asp:FileUpload ID="UpImgName" runat="server"/>控件

    2、在后台.cs中写上

      protected void btnSubmit_Click(object sender,EventArgs e)

    {

      string strImgPath=string.Empty;

      string strDateTime=dateTime.Now.Tostring("yyyyMMddhhmmss");

      strImgPath=this.UpImgPath.PostedFile.FileName;

      if(strImgPath!="")

      {

        string extension="";//扩展名

        extension=Path.GetExtension(strImgPath).ToLower();

        if(extension==".jpg"||extension==".jpeg"||extension==".bmp||extension==""gif")

        {

          if(this.UpImgPath.PostedFile.ContentLength>1000000)//图片大小是否大于1M

          {

            Response.Write("<script>alert('图片太大')</script>");  

            return;    

          }

          strImgPath="/Images/"+strDateTime+extension;

          string UpPath=Server.MapPath(strImgPath);  

          this.UpImgPath.PostedFile.SaveAs(UpPath);    

        }

        else

        {

          Response.Write("<script>alert('图片格式错误')</script>");

          return ;

        }  

      }

    }

    二、视频,文件

    1、在前端用<asp:FileUpload ID="UpVideoName" runat="server"/>控件

    2、在后台.cs中写上

      protected void btnSubmit_Click(object sender,EventArgs e)

    {

      string strVideoPath=string.Empty;

      string strDateTime=DateTime.Now.Tostring("yyyyMMddhhmmss");

      strVideoPath=this.UpVideoName.PostedFile.FileName;

      if(strVideoPath!="")

      {

        string extension="";

        extension=Path.GetExtension(strVideoPath).ToLower();

        if(extension==".flv" || extension == ".doc" || extension == ".docx" || extension == ".zip" || extension == ".rar")

        {

          if(this.UpVideoName.PostedFile.ContentLength>30000000)

          {

            Response.Write("<script>alert('视频或文件太大')</script>");

            return;

          }

          strVideoPath="/VideoOrFile/"+strDateTime+extension;

          string UpPath=Server.MapPath(strVideoPath);

          this.UpVideoName.PostedFile.SaveAs(UpPath);

        }

        else

        {

          Response.Write("<script>alert('存储的格式不正确')</script>")

          return;

        }

      }

    }

    asp.net core 交流群:787464275 欢迎加群交流
    如果您认为这篇文章还不错或者有所收获,您可以点击右下角的【推荐】按钮精神支持,因为这种支持是我继续写作,分享的最大动力!

    作者:LouieGuo
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!

    微信公众号:欢迎关注                                                 QQ技术交流群: 欢迎加群

                    

    LouieGuo
  • 相关阅读:
    Ionic在Generating ES5 bundles for differential loadind的时候报错
    将整个网站变为黑白 CSS3 filter grayscale
    ionic4 sqlite 的 executeSql 方法第二个参数不传会报错
    ionic4 执行ionic cordova run android 时报错Could not find plugin "proposal-numeric-separator". Ensure there is an entry in ./available-plugins.js for it.
    ion-picker组件示例(ionic4),这个组件有样式错乱的问题
    Linux下常用命令
    搜索引擎使用技巧
    Flex布局介绍
    0浏览器内幕探寻--源头
    Geolocation API
  • 原文地址:https://www.cnblogs.com/guolianyu/p/3850226.html
Copyright © 2011-2022 走看看