码迷,mamicode.com
首页 > Web开发 > 详细

上传图片

时间:2015-06-01 14:33:50      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

 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:\T\CRJTSZX" />

 

 

            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;

上传图片

标签:

原文地址:http://www.cnblogs.com/wyBlog117/p/4543805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!