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

文件接收上传

时间:2015-08-06 14:47:42      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

 

    protected void Page_Load(object sender, EventArgs e)
    {

        HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];


        string imageId =DateTime.Now.Ticks.ToString();
        string fileName = Path.GetFileName(jpeg_image_upload.FileName);
        string fileExtension = Path.GetExtension(fileName);
        string uploadName = imageId + fileExtension;


        if (jpeg_image_upload.ContentLength > 0)
        {

            string imageUrl = Server.MapPath("/UpLoadPic/Product/" + DateTime.Now.ToString("yyyyMM") + "/" + uploadName);
            if (!Directory.Exists(Path.GetDirectoryName(imageUrl)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(imageUrl));
            }
            jpeg_image_upload.SaveAs(imageUrl);

            //保存大图并水印
            string bigimg = Server.MapPath("/UpLoadPic/Product/" + DateTime.Now.ToString("yyyyMM") + "/c" + uploadName);
            if (!Directory.Exists(Path.GetDirectoryName(bigimg)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(bigimg));
            }
            NCurrtImg.GreateMiniImage(imageUrl, bigimg, 600, 600, "COM");//生成缩略图
            //CurrtImg.addWaterMark(tempimg, bigimg, "I");//水印


            //保存中图
            string midimg = Server.MapPath("/UpLoadPic/Product/" + DateTime.Now.ToString("yyyyMM") + "/m" + uploadName);
            if (!Directory.Exists(Path.GetDirectoryName(midimg)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(midimg));
            }
            NCurrtImg.GreateMiniImage(imageUrl, midimg, 200, 200, "COM");//生成缩略图

            //保存小图
            string smallimg = Server.MapPath("/UpLoadPic/Product/" + DateTime.Now.ToString("yyyyMM") + "/s" + uploadName);
            if (!Directory.Exists(Path.GetDirectoryName(smallimg)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(smallimg));
            }
            NCurrtImg.GreateMiniImage(imageUrl, smallimg, 33, 33, "COM");//生成缩略图

            Response.StatusCode = 200;
            string returnStr = jpeg_image_upload.ContentLength.ToString();//0 size
            returnStr = returnStr + "|" + "/UpLoadPic/Product/" + DateTime.Now.ToString("yyyyMM") + "/m" + uploadName;//1 url
            returnStr = returnStr + "|" + fileName; //2 title
            returnStr = returnStr + "|" + imageId; //3 id
            returnStr = returnStr + "|" + "wokaokao"; //4 name
            Response.Write(returnStr);
            Response.End();
        }
    }

 

 

    public void SavePic(int brandId)
    {
        HttpFileCollection fileList = HttpContext.Current.Request.Files;
        for (int i = 0; i < fileList.Count; i++)
        {
            HttpPostedFile file = fileList[i];
            string fileName = System.IO.Path.GetFileName(file.FileName);
            string fileExtension = System.IO.Path.GetExtension(fileName);
            string uploadName = brandId + fileExtension;
            string YearMonth = DateTime.Now.ToString("yyyyMM");
            if (file.ContentLength > 0)
            {
                string imgpath = "/UpLoadPic/BrandLogo/" + YearMonth + "/c" + uploadName;

                string smallimg = "";
                string midimg = "";


                JTZK_BrandModel entity = brandBLL.GetEntityModel(brandId);
                entity.BrandLogo = imgpath;
                brandBLL.Update(entity);

                imgpath = "/UpLoadPic/BrandLogo/" + YearMonth + "/c" + uploadName;
                imgpath = Server.MapPath(imgpath);
                file.SaveAs(imgpath);

                smallimg = Server.MapPath("/UpLoadPic/BrandLogo/" + YearMonth + "/s" + uploadName);
                NCurrtImg.GreateMiniImage(imgpath, smallimg, 100, 100, "Cut");

                midimg = Server.MapPath("/UpLoadPic/BrandLogo/" + YearMonth + "/m" + uploadName);
                NCurrtImg.GreateMiniImage(imgpath, midimg, 300, 300, "Cut");

            }
        }

    }

 

    public void SavePic(JTZK_CompanyModel entity)
    {
        HttpFileCollection fileList = HttpContext.Current.Request.Files;
        for (int i = 0; i < fileList.Count; i++)
        {
            HttpPostedFile file = fileList[i];
            string fileName = System.IO.Path.GetFileName(file.FileName);
            string fileExtension = System.IO.Path.GetExtension(fileName);
            string uploadName = entity.Id + fileExtension;

            string YearMonth = DateTime.Now.ToString("yyyyMM");
            if (file.ContentLength > 0)
            {
                string imgpath = "/UpLoadPic/CompanyLogo/" + YearMonth + "/c" + uploadName;
                string smallimg = "";
                string midimg = "";
                entity.CompanyLogo = imgpath;
                JTZK_CompanyBLL bll = new JTZK_CompanyBLL();
                bll.Update(entity);

                imgpath = Server.MapPath(imgpath);
                file.SaveAs(imgpath);

                smallimg = Server.MapPath("/UpLoadPic/CompanyLogo/" + YearMonth + "/s" + uploadName);
                NCurrtImg.GreateMiniImage(imgpath, smallimg, 120, 40, "Cut");

                midimg = Server.MapPath("/UpLoadPic/CompanyLogo/" + YearMonth + "/m" + uploadName);
                NCurrtImg.GreateMiniImage(imgpath, midimg, 240, 80, "Cut");
            }
        }

    }

 

    public void SavePic(JTZK_RegUserModel entity)
    {


        HttpFileCollection fileList = HttpContext.Current.Request.Files;
        for (int i = 0; i < fileList.Count; i++)
        {
            HttpPostedFile file = fileList[i];
            string fileName = System.IO.Path.GetFileName(file.FileName);
            string fileExtension = System.IO.Path.GetExtension(fileName);
            string uploadName = entity.Id + fileExtension;
            string YearMonth = DateTime.Now.ToString("yyyyMM");
            if (file.ContentLength > 0)
            {
                string imgpath = "/UpLoadPic/UserFace/" + YearMonth + "/c" + uploadName;
                string smallimg = "";
                string midimg = "";
                entity.UserFace = imgpath;
                JTZK_RegUserBLL bll = new JTZK_RegUserBLL();
                bll.Update(entity);

                imgpath = Server.MapPath(imgpath);
                file.SaveAs(imgpath);

                smallimg = Server.MapPath("/UpLoadPic/UserFace/" + YearMonth + "/s" + uploadName);
                NCurrtImg.GreateMiniImage(imgpath, smallimg, 100, 100, "W");

                midimg = Server.MapPath("/UpLoadPic/UserFace/" + YearMonth + "/m" + uploadName);
                NCurrtImg.GreateMiniImage(imgpath, midimg, 300, 300, "Cut");
            }
        }

    }

 

文件接收上传

标签:

原文地址:http://www.cnblogs.com/xiaoshi657/p/4707814.html

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