zoukankan      html  css  js  c++  java
  • 上传图片

     var adostream = new ActiveXObject("ADODB.Stream");
                    adostream.Type = 1;
                    adostream.Mode = 3;
                    adostream.Open();
                    adostream.LoadFromFile("D:ScanRaw.jpg");
                    if (adostream.Size > 1024 * 1024 * 10) {
                        delete adostream;
                        return false;
                    }
                    // var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
                    var xmlhttp = xmlhttp = createXMLHttp();
                    xmlhttp.Open("POST", "UploadIdCardjpg.aspx?filename=" + escape("<%=RandomNum%>"), false);
                    xmlhttp.Send(adostream.Read(adostream.Size));
                    var receiveValue = xmlhttp.responseText;
                    adostream.Close();
                    delete adostream;
                    delete xmlhttp;

     protected void Page_Load(object sender, EventArgs e)         {        

         string newstrTime = DateTime.Now.ToString("HH") + "_";        

         string _newfilepath = System.Configuration.ConfigurationManager.AppSettings["SaveFilePath"] + "\" + DateTime.Now.ToString("yyyy") + "\" + DateTime.Now.ToString("yyyyMM");        

        // string newstrfilepath = System.Configuration.ConfigurationManager.AppSettings["vWGFilePath"] + "/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("yyyyMM") + "/";      

           string filename = Request.QueryString["filename"];    

             string newstrImageName = filename + ".jpg";      

           HttpContext context = HttpContext.Current;       

          context.Response.ContentType = "text/plain";       

          if (!System.IO.Directory.Exists(System.IO.Path.Combine(context.Request.PhysicalApplicationPath, _newfilepath)))             {   

                  System.IO.Directory.CreateDirectory(System.IO.Path.Combine(context.Request.PhysicalApplicationPath, _newfilepath));    

             }       

              //利用新传来的路径实例化一个FileStream对象      

           byte[] sf = new byte[Request.InputStream.Length];  //定义byte型数组    

             Request.InputStream.Read(sf, 0, sf.Length);           

      FileStream newfstream = File.Create(_newfilepath + "\" + newstrTime + newstrImageName, sf.Length);      

           try             {          

           newfstream.Write(sf, 0, sf.Length);   //二进制转换成文件         

        }             catch (Exception ex)             {      

               //log.Error("文件保存:" + ex.Message);        

         }             finally             {            

         newfstream.Close();             

        Request.InputStream.Close();

                }

            }

     <add key="vWGFilePath" value="/T/CRJTSZX" />
     <add key="SaveFilePath" value="D:TCRJTSZX" />

                string _newfilepath = System.Configuration.ConfigurationManager.AppSettings["SaveFilePath"] + "\" + DateTime.Now.ToString("yyyy") + "\" + DateTime.Now.ToString("yyyyMM");             string newstrfilepath = System.Configuration.ConfigurationManager.AppSettings["vWGFilePath"] + "/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("yyyyMM") + "/";             if (!_newfilepath.EndsWith("\"))             {                 _newfilepath = _newfilepath + "\";             }             Hzjg.Site.Common.Message msg = new Hzjg.Site.Common.Message();             try             {                 FileInfo _file = new FileInfo(postFile.FileName);                 string sdata = DateTime.Now.ToString("yyyyMM");                 string t = DateTime.Now.ToString("yyyyMMddHHmmss");                 Random dm = new Random();                 long lip = dm.Next(10000);                 string ext = _file.Extension.ToLower();                 string sguid = t + "_" + lip;                 if (!Directory.Exists(_newfilepath))                 {                     Directory.CreateDirectory(_newfilepath);                 }                 string filePath = _newfilepath + sguid + ext;                 int iCount = 0;                 while (File.Exists(filePath))                 {                     sguid = t + "_" + lip + "_" + (++iCount);                     filePath = _newfilepath + sguid + ext;                     if (iCount > 100) break;                 }                 postFile.SaveAs(filePath);

                    newstrfilepath = newstrfilepath.Replace("Temp", "userfiles") + "/" + sguid + ext;                 msg.State = Hzjg.Site.Common.MessageState.Success;                 msg.Msg = newstrfilepath;

  • 相关阅读:
    wtforms 钩子函数
    sqlalchemy 单表增删改查
    sqlalchemy 数据库操作
    flask wtforms组件
    python----------文件操作
    编码 编码的转化
    集合、深浅copy
    字典
    sort 、sorted、range、join方法 数字的正序、倒叙、翻转
    for循环
  • 原文地址:https://www.cnblogs.com/wyBlog117/p/4543805.html
Copyright © 2011-2022 走看看