zblog替换文章里面的老图片
时间:2023年09月15日
/来源:网络
/编辑:佚名
zblog写的,替换EyouCms(易优CMS)文章里的老图片
点击复制代码 PHP
<?php
require 'zb_system/function/c_system_base.php';
$zbp->Load();
$w=array();
$w[]=array('=', 'ccc', "0");
$w[] = array('NOT IN', 'typeid', explode(',','1,4,5,12,17,10,7'));
$sql = $zbp->db->sql->get()->select('ey_archives')->where($w)
->orderBy(array('aid' => 'desc'))
->limit(2800)->sql;
$array = $zbp->db->Query($sql);
foreach ($array as $cc) {
$w=array();
$w[]=array('=', 'aid', $cc['aid']);
$sql = $zbp->db->sql->get()->select('ey_article_content')->where($w)
->limit(1)->query;
$contentold=($sql[0]['content']);
$content=htmlspecialchars_decode($sql[0]['content']);
$ccc=GetImagesFromHtml($content);
if(count($ccc) > 0){
$url=$zbp->path."imgs/";
$img_array= glob($url."*.jpg",GLOB_BRACE);
$num = array_rand($img_array);
$va=$img_array[$num];
$times = time();
$fileName = date("YmdHis", $times) . $times . rand(10000, 99999) . '.jpg';
$fileSavePath = tc_imgssize_getSaveFileDir($times, $fileName);
copy($va, $fileSavePath);
$img=array();
$img[] = '/upload/' . date('Y', $times) . '/' . date('m', $times)."/".$fileName;
unset($va);
$sql = $zbp->db->sql->get()->update('ey_archives')
->where('=', 'aid', $cc['aid'])
->data(array('litpic' => $img[0],'ccc' => '1'))
->query;
print_r($img[0]);
print_r("<br>");
$ddd=$contentold;
foreach ($ccc as $key=>$add) {
if(empty($img[$key])){
$num = array_rand($img_array);
$va=$img_array[$num];
$times = time(); //固定时间
$fileName = date("YmdHis", $times) . $times . rand(10000, 99999) . '.jpg';
$fileSavePath = tc_imgssize_getSaveFileDir($times, $fileName);
copy($va, $fileSavePath);
$img[$key] = '/upload/' . date('Y', $times) . '/' . date('m', $times)."/".$fileName;
unset($va);
}
print_r($img[0]);
print_r("<br>");
print_r($img[$key]);
print_r("<br>");
$ddd=str_replace($add, $img[$key], $ddd);
}
$sql = $zbp->db->sql->get()->update('ey_article_content')
->where('=', 'aid', $cc['aid'])
->data(array('content' => $ddd))
->query;
}else{
$sql = $zbp->db->sql->get()->update('ey_archives')
->where('=', 'aid', $cc['aid'])
->data(array('litpic' => '','ccc' => '1'))
->query;
}
print_r("完成".$cc['aid']);
print_r("<br>");
}
die();
function tc_imgssize_getSaveFileDir($times, $fileName)
{
global $zbp;
$fileDirPath = $zbp->usersdir . 'upload/ccccc/' . date('Y', $times) . '/' . date('m', $times);
if (!file_exists($fileDirPath)) {
@mkdir($fileDirPath, 0755, true);
}
return $fileDirPath . "/" . $fileName;
}
点击复制代码 PHP
<?php
require 'zb_system/function/c_system_base.php';
$zbp->Load();
$w=array();
$w[]=array('=', 'ccc', "0");
$w[] = array('NOT IN', 'typeid', explode(',','1,4,5,12,17,10,7'));
$sql = $zbp->db->sql->get()->select('ey_archives')->where($w)
->orderBy(array('aid' => 'desc'))
->limit(2800)->sql;
$array = $zbp->db->Query($sql);
foreach ($array as $cc) {
$w=array();
$w[]=array('=', 'aid', $cc['aid']);
$sql = $zbp->db->sql->get()->select('ey_article_content')->where($w)
->limit(1)->query;
$contentold=($sql[0]['content']);
$content=htmlspecialchars_decode($sql[0]['content']);
$ccc=GetImagesFromHtml($content);
if(count($ccc) > 0){
$url=$zbp->path."imgs/";
$img_array= glob($url."*.jpg",GLOB_BRACE);
$num = array_rand($img_array);
$va=$img_array[$num];
$times = time();
$fileName = date("YmdHis", $times) . $times . rand(10000, 99999) . '.jpg';
$fileSavePath = tc_imgssize_getSaveFileDir($times, $fileName);
copy($va, $fileSavePath);
$img=array();
$img[] = '/upload/' . date('Y', $times) . '/' . date('m', $times)."/".$fileName;
unset($va);
$sql = $zbp->db->sql->get()->update('ey_archives')
->where('=', 'aid', $cc['aid'])
->data(array('litpic' => $img[0],'ccc' => '1'))
->query;
print_r($img[0]);
print_r("<br>");
$ddd=$contentold;
foreach ($ccc as $key=>$add) {
if(empty($img[$key])){
$num = array_rand($img_array);
$va=$img_array[$num];
$times = time(); //固定时间
$fileName = date("YmdHis", $times) . $times . rand(10000, 99999) . '.jpg';
$fileSavePath = tc_imgssize_getSaveFileDir($times, $fileName);
copy($va, $fileSavePath);
$img[$key] = '/upload/' . date('Y', $times) . '/' . date('m', $times)."/".$fileName;
unset($va);
}
print_r($img[0]);
print_r("<br>");
print_r($img[$key]);
print_r("<br>");
$ddd=str_replace($add, $img[$key], $ddd);
}
$sql = $zbp->db->sql->get()->update('ey_article_content')
->where('=', 'aid', $cc['aid'])
->data(array('content' => $ddd))
->query;
}else{
$sql = $zbp->db->sql->get()->update('ey_archives')
->where('=', 'aid', $cc['aid'])
->data(array('litpic' => '','ccc' => '1'))
->query;
}
print_r("完成".$cc['aid']);
print_r("<br>");
}
die();
function tc_imgssize_getSaveFileDir($times, $fileName)
{
global $zbp;
$fileDirPath = $zbp->usersdir . 'upload/ccccc/' . date('Y', $times) . '/' . date('m', $times);
if (!file_exists($fileDirPath)) {
@mkdir($fileDirPath, 0755, true);
}
return $fileDirPath . "/" . $fileName;
}
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法