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"); //上传成功   
    •         }  
    •     }  
  • 相关阅读:
    第五周 day5 python学习笔记
    第四周 day4 python学习笔记
    第三周 day3 python学习笔记
    常用屏幕分辨率
    学习可以借鉴的大牛们的网站
    jq动态控制样式的一些方法(批量控制样式,带参数控制样式)
    jq实现事件委托
    h5Css新加的一些新的属性
    css布局模型
    task_13
  • 原文地址:https://www.cnblogs.com/linsu/p/2228554.html
Copyright © 2011-2022 走看看