关于微博图床限制外链图片后网站图片本地化的问题解决

今日微博图床限制外链图片的调用,已经给广大站长敲响了警钟,顺便提个醒就是告诉站长们赶紧进行新浪图床相关图片的转移,关于使用微博图床的网站图片显示403,网上关于微博图床限制外链图片显示403的问题给出了方法和教程,但都是治标不治本,对于网站内容较少的站长转移来说可能很简单顺利,但对于网站内容较多的站长就是个大工程了,网上给出的方法也无异于饮鸩止渴,唯一的方法还是图片本地化,杜绝图床图片,当属上策!

微博图床防盗链

微博图床防盗链

关于外链图片本地化,网上也有大佬给出了方法如下:

python爬虫
获取全站文章链接(这个以前写过相关文章WordPress获取所有文章链接)
python写爬虫一篇篇爬数据后,用re模块正则表达式findall()方法筛选出所有图片链接。等等,

但对于小白来说这些就太困难了,小编就在想,能不能有插件可以用,于是小编就找到了这款插件QQworld

微博图床防盗链

微博图床防盗链

大家可以到自己wordpress后台——插件——安装插件,然后搜索这个插件的名称即可安装使用。

QQword自动保存图片本站下载:

立即下载 

温馨提示:隐藏内容需要您点击本站任一google广告并评论后可见,审核通过请刷新页面!您的支持是我们为您提供优质内容的动力!

关于QQword自动保存图片怎么使用:

1.打开网站后台——设置——QQword自动保存图片——找到扫描文章(这里勾选相应栏目的文章,也可以选择全部文章,扫描完成会显示相应的文章列表)

微博图床防盗链图片本地化

微博图床防盗链图片本地化

2。勾选所有文章,进行手动扫描(PS:也可进行自动,注意备份数据库)

微博图床防盗链图片本地化

微博图床防盗链图片本地化

3.进行抓取,也可以连续点击列表里的抓取以加快速度,如图,正在抓取中。。。。。。

微博图床防盗链图片本地化

微博图床防盗链图片本地化

4.抓取完成,已自动保存到媒体库

微博图床防盗链图片本地化

微博图床防盗链图片本地化

如此就完成了微博图床防盗链微博图床外链图床图片本地化。就不用在担心图床挂了!

还有一种代码方法,修改模版函数的代码:

复制下面的代码,然后粘贴到你当前WordPress主题的模版函数(functions.php)文件中保存即可。

//自动本地化外链图片
add_filter('content_save_pre', 'auto_save_image');
function auto_save_image($content) {
$upload_path = '';
$upload_url_path = get_bloginfo('url');
//上传目录
if (($var = get_option('upload_path')) !=''){
$upload_path = $var;
} else {
$upload_path = 'wp-content/uploads';
}
if(get_option('uploads_use_yearmonth_folders')) {
$upload_path .= '/'.date("Y",time()).'/'.date("m",time());
}
//文件地址
if(($var = get_option('upload_url_path')) != '') {
$upload_url_path = $var;
} else {
$upload_url_path = bloginfo('url');
}
if(get_option('uploads_use_yearmonth_folders')) {
$upload_url_path .= '/'.date("Y",time()).'/'.date("m",time());
}
require_once ("../wp-includes/class-snoopy.php");
$snoopy_Auto_Save_Image = new Snoopy;
$img = array();
//以文章的标题作为图片的标题
if ( !emptyempty( $_REQUEST['post_title'] ) )
$post_title = wp_specialchars( stripslashes( $_REQUEST['post_title'] ));
$text = stripslashes($content);
if (get_magic_quotes_gpc()) $text = stripslashes($text);
preg_match_all("/ src=(\"|\'){0,}(http:\/\/(.+?))(\"|\'|\s)/is",$text,$img);
$img = array_unique(dhtmlspecialchars($img[2]));
foreach ($img as $key => $value){
set_time_limit(180); //每个图片最长允许下载时间,秒
if(str_replace(get_bloginfo('url'),"",$value)==$value&&str_replace(get_bloginfo('home'),"",$value)==$value){
//判断是否是本地图片,如果不是,则保存到服务器
$fileext = substr(strrchr($value,'.'),1);
$fileext = strtolower($fileext);
if($fileext==""||strlen($fileext)>4)
$fileext = "jpg";
$savefiletype = array('jpg','gif','png','bmp');
if (in_array($fileext, $savefiletype)){
if($snoopy_Auto_Save_Image->fetch($value)){
$get_file = $snoopy_Auto_Save_Image->results;
}else{
echo "error fetching file: ".$snoopy_Auto_Save_Image->error."<br>";
echo "error url: ".$value;
die();
}
$filetime = time();
$filepath = "/".$upload_path;//图片保存的路径目录
!is_dir("..".$filepath) ? mkdirs("..".$filepath) : null;
//$filename = date("His",$filetime).random(3);
$filename = substr($value,strrpos($value,'/'),strrpos($value,'.')-strrpos($value,'/'));
//$e = '../'.$filepath.$filename.'.'.$fileext;
//if(!is_file($e)) {
// copy(htmlspecialchars_decode($value),$e);
//}
$fp = @fopen("..".$filepath.$filename.".".$fileext,"w");
@fwrite($fp,$get_file);
fclose($fp);
$wp_filetype = wp_check_filetype( $filename.".".$fileext, false );
$type = $wp_filetype['type'];
$post_id = (int)$_POST['temp_ID2'];
$title = $post_title;
$url = $upload_url_path.$filename.".".$fileext;
$file = $_SERVER['DOCUMENT_ROOT'].$filepath.$filename.".".$fileext;
//添加数据库记录
$attachment = array(
'post_type' => 'attachment',
'post_mime_type' => $type,
'guid' => $url,
'post_parent' => $post_id,
'post_title' => $title,
'post_content' => '',
);
$id = wp_insert_attachment($attachment, $file, $post_parent);
$text = str_replace($value,$url,$text); //替换文章里面的图片地址
}
}
}
$content = AddSlashes($text);
remove_filter('content_save_pre', 'auto_save_image');
return $content;
}
function mkdirs($dir)
{
if(!is_dir($dir))
{
mkdirs(dirname($dir));
mkdir($dir);
}
return ;
}
function dhtmlspecialchars($string) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = dhtmlspecialchars($val);
}
}else{
$string = str_replace('&', '&', $string);
$string = str_replace('"', '"', $string);
$string = str_replace('<', '<', $string);
$string = str_replace('>', '>', $string);
$string = preg_replace('/&(#\d;)/', '&\1', $string);
}
return $string;
}

这个代码的功能就是自动把你复制来的外链图片转变成本地图片,文章中的图片会自动本地化。不过呢这个代码是来自于一篇文章,原文地址http://www.1mayi.com/4732.html,至于效果嘛,博主不知道,博主用的插件,第二种方法大家需要自己测试一下!

新浪图床外链图片不显示(403)解决办法

上一篇

最新流畅央视CCTV卫视直播源【20190428】

下一篇

99%的人还看了

发表评论

插入图片

欢迎登陆本站

 | 注册


耗时 0.226 秒 查询 19 次 内存 8.68 MB

在线工具

VIP视频解析
注册

登录

忘记密码 ?