# 织梦远程图片如何本地化https站点图片教程

*Published:* 2023-07-27
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年7月29日，已超过 180天没有更新



在使用织梦DEDECMS时,很多时候从一些网站复制的内容时,其中的图片,保存时不能把远程图片下载到本地,像新浪博客,网易等一些大型网站图片有做防盗链处理,图片地址并没有后辍名!因此在使用dedecms默认的下载远程功能没办法实现!

对于http的远程图片本地化，dedecms能很好解决，但是碰到[https](https://www.xarjtc.com/tag/https "查看https此标签更多文章")的就无法本地化了，以下是解决办法：

找到dede/inc/inc\_archives\_functions.php文件里面GetCurContent($body)这个函数，里面

```
preg_match_all("/src=[\"|'|\s]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
$img_array = array_unique($img_array[1]);
```

这一段改为：

```
$img_array = array();   //普通图片
$bgimg_array = array(); //背景图片
$img_array_https = array();
preg_match_all("/<img[^>]*src=[\"|'|\s]{0,}(http:\/\/([^>]*))(\"|'|\s)/isU",$body,$img_array);
preg_match_all("/<img[^>]*src=[\"|'|\s]{0,}(https:\/\/([^>]*))(\"|'|\s)/isU",$body,$img_array_https);
preg_match_all("/.*background[^;\"]+url\(([^\)]+)\).*/isU",$body,$bgimg_array);
$img_array = array_unique($img_array[1]); 
$bgimg_array = array_unique($bgimg_array[1]); 
$img_array_https = array_unique($img_array_https[1]); 
$img_array=array_merge_recursive($img_array,$bgimg_array,$img_array_https);
```

再找到

```
if(!preg_match("#^http:\/\/#i", $value))
{
    continue;
}
```

改为

```
if(!preg_match("#^(http|https):\/\/#i", $value))
{
    continue;
}
```