当前位置:编程学习 > html/css >>

下载图片并上传至图片服务器

 

[html]
#region  下载图片并上传至图片服务器 
        public  string SaveUrlPics(  string strHTML, string path) 
        { 
            string picserver = new CommonBLL().GetItemValue("PICSERVER");//获取图片服务器地址 
            string[] imgurlAry = GetImgTag(strHTML);//获取文章中的图片地址 
            try 
            {      
                WebClient wc = new WebClient(); 
                for (int i = 0; i < imgurlAry.Length; i++) 
                { 
                    //暂时处理避免多次进行添加处理 不处理本机的情况 
                    if(imgurlAry[i].IndexOf(picserver)<0) 
                    { 
                    string preStr = DateTime.Now.ToString("yyyyMMddHHmmssfff"); 
                    preStr = preStr + imgurlAry[i].Substring(imgurlAry[i].LastIndexOf("."));//获取图片的属性 生成图片名称 
                     //下载的图片存储在TEMP文件夹中 
                    wc.DownloadFile(imgurlAry[i], HttpContext.Current.Server.MapPath(path) + "/" + preStr); 
                    //把图片上传至图片服务器 
                    preStr = picserver + "/" + upImg(preStr,  dropArtType.SelectedValue); 
                    strHTML = strHTML.Replace(imgurlAry[i], preStr); 
                    } 
                }     
            } 
            catch (Exception ex) 
            { 
                ShowMessage(ex.Message); 
            } 
            return strHTML; 
        } 
 
        #endregion 

#region  下载图片并上传至图片服务器
        public  string SaveUrlPics(  string strHTML, string path)
        {
            string picserver = new CommonBLL().GetItemValue("PICSERVER");//获取图片服务器地址
            string[] imgurlAry = GetImgTag(strHTML);//获取文章中的图片地址
            try
            {    
                WebClient wc = new WebClient();
                for (int i = 0; i < imgurlAry.Length; i++)
                {
                    //暂时处理避免多次进行添加处理 不处理本机的情况
                    if(imgurlAry[i].IndexOf(picserver)<0)
                    {
                    string preStr = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    preStr = preStr + imgurlAry[i].Substring(imgurlAry[i].LastIndexOf("."));//获取图片的属性 生成图片名称
                     //下载的图片存储在TEMP文件夹中
                    wc.DownloadFile(imgurlAry[i], HttpContext.Current.Server.MapPath(path) + "/" + preStr);
                    //把图片上传至图片服务器
                    preStr = picserver + "/" + upImg(preStr,  dropArtType.SelectedValue);
                    strHTML = strHTML.Replace(imgurlAry[i], preStr);
                    }
                }   
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
            return strHTML;
        }

        #endregion

 

补充:web前端 , HTML/CSS  ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,