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;

  • 相关阅读:
    IIS7.5 部署WCF项目问题集锦
    C#制作“安装和部署”时,实现软件开机启动
    Strsafe.h:更安全的C语言字符串处理函数
    FMOD音频引擎简单使用
    您也使用托管C++吗?
    《Programming in Lua中文版》 8.Compilation, Execution, and Errors
    恶心的C语言strtok函数
    Lua一些基本函数
    Lua tables 分析1
    如何让EditPlus支持LUA(转)
  • 原文地址:https://www.cnblogs.com/wyBlog117/p/4543805.html
Copyright © 2011-2022 走看看