zoukankan      html  css  js  c++  java
  • 文件上传到Web服务器

    1.添加需要的控件

      <form id="uploderform" method="post" action="fileupload.ashx" enctype="multipart/form-data"  runat="server" >

     文件名称:  <input type="file" id="myfile" runat="server" name="myfile">

                     <input type="button"  value="上 传"  id="fileupload" name="upload">

     </form >

    2 ashx文件

     public void ProcessRequest (HttpContext context) {  

    •         HttpPostedFile _upfile = context.Request.Files["File1"];  
    •         if (_upfile == null)  
    •         {  
    •             ResponseWriteEnd(context, "4");//请选择要上传的文件   
    •         }  
    •         else  
    •         {  
    •             string fileName = _upfile.FileName;/*获取文件名: C:\Documents and Settings\Administrator\桌面\123.jpg*/  
    •             string suffix = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();/*获取后缀名并转为小写: jpg*/  
    •             int bytes = _upfile.ContentLength;//获取文件的字节大小   
    •   
    •             if (suffix != "jpg")  
    •                 ResponseWriteEnd(context, "2"); //只能上传JPG格式图片   
    •             if (bytes > 1024 * 1024)  
    •                 ResponseWriteEnd(context, "3"); //图片不能大于1M   
    •   
    •             _upfile.SaveAs(HttpContext.Current.Server.MapPath("~/images/logo.jpg"));//保存图片   
    •             ResponseWriteEnd(context, "1"); //上传成功   
    •         }  
    •     }  
  • 相关阅读:
    python的argparse模块
    Robotframework之SSHLibrary库
    Python 中的 getopt 模块
    Python list 列表
    Samba windows 10 share: mount error(112): Host is down
    安装两个版本的python安装包,后安装的python程序打开时闪退
    NetScaler VPX configration
    drupal smtp could not connect to smtp
    drupal7 判断用户是否具有某个权限
    微信支付报错:time_expire时间过短,刷卡至少1分钟,其他5分钟]
  • 原文地址:https://www.cnblogs.com/linsu/p/2228554.html
Copyright © 2011-2022 走看看