wordpress转xiuno附件自动插入工具

Home / Article MrLee 2019-1-3 4169

自wordpress转xiuno已经有一年多,之前发现很多图片都没有缩略图一直没弄,今天抽空写了一个小工具,自动把wp的图片写入数据库。前提工作把wp的附件目录移动到xiuno的upload/attach/wp目录下,然后执行下面代码即可。

<?php 
header("Content-type: text/html; charset=UTF-8");
function macth_imgs($content){
	preg_match_all('/<img.*?src="(.*?)"/',$content,$thread_all_img);
	if(count($thread_all_img)>0){
		//索引0不带/符号的地址 索引1带/符号
		$thread_all_imgs = array_unique($thread_all_img[1]);
		$img_path = $thread_all_imgs[0];
		if(strpos($img_path,'/') === 0)
			$img_path = substr(1,strlen($img_path));
		return $img_path;//只取第一张图地址
	}
	return false;
}
function insert_attach(){
	set_time_limit(0);
	require_once('db/db.php');
	$result = db_query('SELECT * FROM bbs.bbs_post WHERE message LIKE "%upload/attach/wp%"');
	if(empty($result))return;
	foreach($result as $key=>$val){
		$img = macth_imgs($val->message);
		if($img){
			$img = str_replace('http://www.it72.com/upload/attach/wp','wp',$img);
			$img_info = getimagesize('upload/attach/'.$img);
			if($img_info == false)continue;
			echo '<hr/>';
			$sql = 'INSERT INTO bbs.bbs_attach(tid,pid,uid,filesize,width,height,filename,orgfilename,filetype,create_date,isimage)VALUES('.$val->tid.','.$val->pid.',1,'.filesize('upload/attach/'.$img).','.$img_info[0].','.$img_info[1].',"'.$img.'","'.$img_info['mime'].'","image",1505520732,1);';
			$ret = db_query($sql);
			echo $sql;
		}
	}
	echo '<hr/>Done.';
}
if(isset($_GET['cmd'])){
	insert_attach();
}else{
	echo 'v1.0.3';
}
?>

需要注意的是,代码图片提取默认只取一张,因为我的缩略图只需要一张,多了也无用。不浪费数据库空间


本文链接:https://www.it72.com/12458.htm

推荐阅读
最新回复 (1)
返回