迅睿CMS框架是一款PHP8高性能·簡(jiǎn)單易用的CMS開源開發(fā)框架,基于MIT開源許可協(xié)議發(fā)布,免費(fèi)且不限制商業(yè)使用,是免費(fèi)開源的產(chǎn)品,以萬端互聯(lián)為設(shè)計(jì)理念,支持的微信公眾號(hào)、小程序、APP客戶端、移動(dòng)端網(wǎng)站、PC網(wǎng)站等多終端式管理系統(tǒng)。
聯(lián)系官方銷售客服
1835022288
028-61286886
經(jīng)過多人指點(diǎn),終于把火車頭保存圖片到本地和提取縮略圖搞好了,馬上分享出來,有需要的自己下載吧,盡量打賞支持下,不容易啊1922135201
16346314896e4fc3.zip
1
回復(fù)@陳楓seo 哪里搞不定的可以問我,我采集了7,8遍都沒有問題
111
發(fā)布者隨機(jī)有搞定嗎,需要寫php數(shù)組
2
謝謝分享!
學(xué)習(xí)學(xué)習(xí)123
不錯(cuò)喲 來看看
回復(fù)@微云小編 可以
好人一生平安
回復(fù)@微云小編 可以搞定
看看效果
學(xué)習(xí)了,點(diǎn)個(gè)贊。 ??
試試效果
需要回復(fù)后才能看到
學(xué)習(xí)學(xué)習(xí)
解壓密碼多少啊大神
回復(fù)看看試試,先謝謝大佬
回復(fù)@sorrymybaby 有個(gè)壓縮包的,解壓密碼應(yīng)該是ltjmm
感謝大佬通過的代碼兼容匹配這種圖片 加強(qiáng)版 代碼如下
<?php
$this->_module_init('news'); // news 是模塊目錄
if ($_GET['action'] == 'category')
{
// 顯示欄目
if (!$this->module['category'])
echo '模塊【' . $this->module['dirname'] . '】沒有創(chuàng)建欄目';
}
foreach ($this->module['category'] as $t)
if ($t['child'] == 0 && $t['tid'] == 1)
echo '<h1>' . $t['name'] . '<=>' . $t['id'] . '</h1>' . PHP_EOL;
else
// 入庫(kù)數(shù)據(jù)
$data = $_REQUEST;
// 發(fā)布者id 1
$data['uid'] = 1;
// 發(fā)布者賬號(hào) admin
$data['author'] = 'admin';
// 主表字段
$fields[1] = $this->get_cache('table-' . SITE_ID, $this->content_model->dbprefix(SITE_ID . '_' . MOD_DIR));
$cache = $this->get_cache('table-' . SITE_ID, $this->content_model->dbprefix(SITE_ID . '_' . MOD_DIR . '_category_data'));
$cache && $fields[1] = array_merge($fields[1], $cache);
// 附表字段
$fields[0] = $this->get_cache('table-' . SITE_ID, $this->content_model->dbprefix(SITE_ID . '_' . MOD_DIR . '_data_0'));
// 去重復(fù)
$fields[0] = array_unique($fields[0]);
$fields[1] = array_unique($fields[1]);
// 格式化入庫(kù)字段
// 一般是格式化非文本類的字段(例如多文件上傳、復(fù)選框、聯(lián)動(dòng)字段等等)
// 這里需要按采集資料的格式入庫(kù)格式化字段,
// 開始?xì)w類存儲(chǔ)
$save = [];
// 主表附表歸類
foreach ($fields as $ismain => $field)
foreach ($field as $name)
isset($data[$name]) && $save[$ismain][$name] = $data[$name];
if (!$data['catid'])
exit('欄目為空');
$save[1]['uid'] = $save[0]['uid'] = $data['uid'];
$save[1]['catid'] = $save[0]['catid'] = $data['catid'];
$save[1]['url'] = '';
$save[1]['status'] = 9; //9表示正常發(fā)布,1表示審核里面
$save[1]['hits'] = 0;
$save[1]['displayorder'] = 0;
$save[1]['link_id'] = 0;
$save[1]['inputtime'] = $save[1]['updatetime'] = SYS_TIME + rand(0, 7200);
$save[1]['inputip'] = '127.0.0.1';
//$save[1]['keywords'] = dr_get_keywords( $save[1]['title']); // 按插件提取關(guān)鍵詞
//$save[1]['description'] = dr_get_description( $save[0]['content'], 100); // 在內(nèi)容里面提取100個(gè)子作為描述
// 驗(yàn)證標(biāo)題重復(fù)
if ($this->content_model->table(SITE_ID . '_' . MOD_DIR)->where('title', $save[1]['title'])->counts())
echo '重復(fù)';
exit;
// 文檔內(nèi)容
$value = $data['content'];
// 第一張作為縮略圖
$slt = 1;
// 是否下載圖片
$yct = 1;
$base64 = strpos($value, ';base64,');
// 附件入庫(kù)標(biāo)記字符
$rid = md5(FC_NOW_URL.\Phpcmf\Service::L('input')->get_user_agent().\Phpcmf\Service::L('input')->ip_address().\Phpcmf\Service::C()->uid);
// 下載遠(yuǎn)程圖片
if ($yct || $slt || $base64) {
$temp = preg_replace('/<pre(.*)<\/pre>/siU', '', $value);
$temp = preg_replace('/<code(.*)<\/code>/siU', '', $temp);
if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+)\\2/i", $temp, $imgs)) {
foreach ($imgs[3] as $img) {
if ($base64 && preg_match('/^(data:\s*image\/(\w+);base64,)/i', $img, $result)) {
// 處理圖片
$ext = strtolower($result[2]);
if (!in_array($ext, ['png', 'jpg', 'jpeg', 'gif', 'webp'])) {
continue;
$content = base64_decode(str_replace($result[1], '', $img));
if (strlen($content) > 30000000) {
$rt = \Phpcmf\Service::L('upload')->base64_image([
'ext' => $ext,
'content' => $content,
'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0,
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']),
]);
if (!$rt['code']) {
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$rid);
if ($att['code']) {
// 歸檔成功
$value = str_replace($img, $rt['data']['url'], $value);
$img = $att['code'];
// 標(biāo)記附件
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($rid, $att['code']);
} else {
$ext = _get_image_ext($img);
if (!$ext) {
// 下載圖片
if ($yct && strpos($img, 'http') === 0) {
if (dr_is_app('mfile') && \Phpcmf\Service::M('mfile', 'mfile')->check_upload(\Phpcmf\Service::C()->uid)) {
//用戶存儲(chǔ)空間已滿
// 正常下載
// 判斷域名白名單
$arr = parse_url($img);
$domain = $arr['host'];
if ($domain) {
$sites = \Phpcmf\Service::R(WRITEPATH.'config/domain_site.php');
if (isset($sites[$domain])) {
// 過濾站點(diǎn)域名
} elseif (strpos(SYS_UPLOAD_URL, $domain) !== false) {
// 過濾附件白名單
$zj = 0;
$remote = \Phpcmf\Service::C()->get_cache('attachment');
if ($remote) {
foreach ($remote as $t) {
if (strpos($t['url'], $domain) !== false) {
$zj = 1;
break;
if ($zj == 0) {
// 可以下載文件
// 下載遠(yuǎn)程文件
$rt = \Phpcmf\Service::L('upload')->down_file([
'url' => $img,
'timeout' => 5,
'file_ext' => $ext,
if ($rt['code']) {
// 縮略圖
if ($img && $slt) {
$_field = \Phpcmf\Service::L('form')->fields;
if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb']) {
if (!is_numeric($img)) {
// 下載縮略圖
$file = dr_catcher_data($img, 8);
if (!$file) {
CI_DEBUG(@反饋BUG) && log_message('debug', '服務(wù)器無法下載圖片:'.$img);
// 嘗試找一找附件庫(kù)
$att = \Phpcmf\Service::M()->table('attachment')->like('related', 'ueditor')->where('filemd5', md5($file))->getRow();
if ($att) {
$img = $att['id'];
// 下載歸檔
'file_content' => $file,
\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb'] = $_POST['data']['thumb'] = $img;
// 最后得到的文檔內(nèi)容
$save[0]['content'] = $value;
// 最后得到的縮略圖
$save[1]['thumb'] = $img;
$rt = $this->content_model->save_content(0, $save);
if ($rt['code'])
/*
// 用于發(fā)布成功后生成靜態(tài)文件代碼
//dr_html_auth($_SERVER['SERVER_ADDR']);
//dr_catcher_data(SITE_URL.'index.php?s='.MOD_DIR.'&c=html&m=showfile&id='.$rt['id']);
$atcode = 'chtml_'.SITE_ID.'_'.MOD_DIR.'_'.$rt['code'];
\Phpcmf\Service::L('cache')->set_auth_data($atcode, $rt['code'], SITE_ID);
dr_catcher_data(SITE_URL.'index.php?s='.MOD_DIR.'&c=html&m=showfile&id='.$rt['code'].'&atcode='.$atcode);
*/
exit('成功');
exit('失敗');
// 獲取遠(yuǎn)程附件擴(kuò)展名
function _get_image_ext($url) {
if (strlen($url) > 300) {
return '';
$arr = ['gif', 'jpg', 'jpeg', 'png', 'webp'];
$ext = str_replace('.', '', trim(strtolower(strrchr($url, '.')), '.'));
if ($ext && in_array($ext, $arr)) {
return $ext; // 滿足擴(kuò)展名
} elseif ($ext && strlen($ext) < 4) {
//CI_DEBUG(@反饋BUG) && log_message('error', '此路徑不是遠(yuǎn)程圖片:'.$url);
return ''; // 表示不是圖片擴(kuò)展名了
foreach ($arr as $t) {
if (stripos($url, $t) !== false) {
return $t;
$rt = getimagesize($url);
if ($rt && $rt['mime']) {
if (stripos($rt['mime'], $t) !== false) {
CI_DEBUG(@反饋BUG) && log_message('debug', '服務(wù)器無法獲取遠(yuǎn)程圖片的擴(kuò)展名:'.dr_safe_replace($url));
發(fā)布失敗,錯(cuò)誤信息:
網(wǎng)頁(yè)源代碼:
返回的Header:
HTTP/1.1 200 OK
Server:nginx/1.15.11
Date:Sat, 29 Jan 2022 18:31:00 GMT
Content-Type:text/html; charset=utf-8
Transfer-Encoding:chunked
Connection:keep-alive
X-Powered-By:PHP/7.3.4
Content-Length:6
看看看看?。。?br/>
學(xué)習(xí)一下
好人一聲平安
我要下載
1
回復(fù)@陳楓seo 哪里搞不定的可以問我,我采集了7,8遍都沒有問題
111
1
1
1
發(fā)布者隨機(jī)有搞定嗎,需要寫php數(shù)組
2
謝謝分享!
學(xué)習(xí)學(xué)習(xí)123
不錯(cuò)喲 來看看
不錯(cuò)喲 來看看
回復(fù)@微云小編 可以
好人一生平安
回復(fù)@微云小編 可以搞定
看看效果
學(xué)習(xí)了,點(diǎn)個(gè)贊。 ??
試試效果
學(xué)習(xí)了,點(diǎn)個(gè)贊。 ??
需要回復(fù)后才能看到
學(xué)習(xí)學(xué)習(xí)
學(xué)習(xí)學(xué)習(xí)
學(xué)習(xí)學(xué)習(xí)
解壓密碼多少啊大神
回復(fù)看看試試,先謝謝大佬
回復(fù)@微云小編 可以
回復(fù)@sorrymybaby 有個(gè)壓縮包的,解壓密碼應(yīng)該是ltjmm
感謝大佬通過的代碼
兼容匹配這種圖片 加強(qiáng)版 代碼如下
<?php
$this->_module_init('news'); // news 是模塊目錄
if ($_GET['action'] == 'category')
{
// 顯示欄目
if (!$this->module['category'])
{
echo '模塊【' . $this->module['dirname'] . '】沒有創(chuàng)建欄目';
}
foreach ($this->module['category'] as $t)
{
if ($t['child'] == 0 && $t['tid'] == 1)
{
echo '<h1>' . $t['name'] . '<=>' . $t['id'] . '</h1>' . PHP_EOL;
}
}
}
else
{
// 入庫(kù)數(shù)據(jù)
$data = $_REQUEST;
// 發(fā)布者id 1
$data['uid'] = 1;
// 發(fā)布者賬號(hào) admin
$data['author'] = 'admin';
// 主表字段
$fields[1] = $this->get_cache('table-' . SITE_ID, $this->content_model->dbprefix(SITE_ID . '_' . MOD_DIR));
$cache = $this->get_cache('table-' . SITE_ID, $this->content_model->dbprefix(SITE_ID . '_' . MOD_DIR . '_category_data'));
$cache && $fields[1] = array_merge($fields[1], $cache);
// 附表字段
$fields[0] = $this->get_cache('table-' . SITE_ID, $this->content_model->dbprefix(SITE_ID . '_' . MOD_DIR . '_data_0'));
// 去重復(fù)
$fields[0] = array_unique($fields[0]);
$fields[1] = array_unique($fields[1]);
// 格式化入庫(kù)字段
// 一般是格式化非文本類的字段(例如多文件上傳、復(fù)選框、聯(lián)動(dòng)字段等等)
// 這里需要按采集資料的格式入庫(kù)格式化字段,
// 開始?xì)w類存儲(chǔ)
$save = [];
// 主表附表歸類
foreach ($fields as $ismain => $field)
{
foreach ($field as $name)
{
isset($data[$name]) && $save[$ismain][$name] = $data[$name];
}
}
if (!$data['catid'])
{
exit('欄目為空');
}
$save[1]['uid'] = $save[0]['uid'] = $data['uid'];
$save[1]['catid'] = $save[0]['catid'] = $data['catid'];
$save[1]['url'] = '';
$save[1]['status'] = 9; //9表示正常發(fā)布,1表示審核里面
$save[1]['hits'] = 0;
$save[1]['displayorder'] = 0;
$save[1]['link_id'] = 0;
$save[1]['inputtime'] = $save[1]['updatetime'] = SYS_TIME + rand(0, 7200);
$save[1]['inputip'] = '127.0.0.1';
//$save[1]['keywords'] = dr_get_keywords( $save[1]['title']); // 按插件提取關(guān)鍵詞
//$save[1]['description'] = dr_get_description( $save[0]['content'], 100); // 在內(nèi)容里面提取100個(gè)子作為描述
// 驗(yàn)證標(biāo)題重復(fù)
if ($this->content_model->table(SITE_ID . '_' . MOD_DIR)->where('title', $save[1]['title'])->counts())
{
echo '重復(fù)';
exit;
}
// 文檔內(nèi)容
$value = $data['content'];
// 第一張作為縮略圖
$slt = 1;
// 是否下載圖片
$yct = 1;
$base64 = strpos($value, ';base64,');
// 附件入庫(kù)標(biāo)記字符
$rid = md5(FC_NOW_URL.\Phpcmf\Service::L('input')->get_user_agent().\Phpcmf\Service::L('input')->ip_address().\Phpcmf\Service::C()->uid);
// 下載遠(yuǎn)程圖片
if ($yct || $slt || $base64) {
$temp = preg_replace('/<pre(.*)<\/pre>/siU', '', $value);
$temp = preg_replace('/<code(.*)<\/code>/siU', '', $temp);
if (preg_match_all("/(src)=([\"|']?)([^ \"'>]+)\\2/i", $temp, $imgs)) {
foreach ($imgs[3] as $img) {
if ($base64 && preg_match('/^(data:\s*image\/(\w+);base64,)/i', $img, $result)) {
// 處理圖片
$ext = strtolower($result[2]);
if (!in_array($ext, ['png', 'jpg', 'jpeg', 'gif', 'webp'])) {
continue;
}
$content = base64_decode(str_replace($result[1], '', $img));
if (strlen($content) > 30000000) {
continue;
}
$rt = \Phpcmf\Service::L('upload')->base64_image([
'ext' => $ext,
'content' => $content,
'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0,
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']),
]);
if (!$rt['code']) {
continue;
}
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$rid);
if ($att['code']) {
// 歸檔成功
$value = str_replace($img, $rt['data']['url'], $value);
$img = $att['code'];
// 標(biāo)記附件
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($rid, $att['code']);
}
} else {
$ext = _get_image_ext($img);
if (!$ext) {
continue;
}
// 下載圖片
if ($yct && strpos($img, 'http') === 0) {
if (dr_is_app('mfile') && \Phpcmf\Service::M('mfile', 'mfile')->check_upload(\Phpcmf\Service::C()->uid)) {
//用戶存儲(chǔ)空間已滿
} else {
// 正常下載
// 判斷域名白名單
$arr = parse_url($img);
$domain = $arr['host'];
if ($domain) {
$sites = \Phpcmf\Service::R(WRITEPATH.'config/domain_site.php');
if (isset($sites[$domain])) {
// 過濾站點(diǎn)域名
} elseif (strpos(SYS_UPLOAD_URL, $domain) !== false) {
// 過濾附件白名單
} else {
$zj = 0;
$remote = \Phpcmf\Service::C()->get_cache('attachment');
if ($remote) {
foreach ($remote as $t) {
if (strpos($t['url'], $domain) !== false) {
$zj = 1;
break;
}
}
}
if ($zj == 0) {
// 可以下載文件
// 下載遠(yuǎn)程文件
$rt = \Phpcmf\Service::L('upload')->down_file([
'url' => $img,
'timeout' => 5,
'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0,
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']),
'file_ext' => $ext,
]);
if ($rt['code']) {
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$rid);
if ($att['code']) {
// 歸檔成功
$value = str_replace($img, $rt['data']['url'], $value);
$img = $att['code'];
// 標(biāo)記附件
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($rid, $att['code']);
}
}
}
}
}
}
}
}
// 縮略圖
if ($img && $slt) {
$_field = \Phpcmf\Service::L('form')->fields;
if (isset($_field['thumb']) && $_field['thumb']['fieldtype'] == 'File' && !\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb']) {
if (!is_numeric($img)) {
// 下載縮略圖
// 判斷域名白名單
$arr = parse_url($img);
$domain = $arr['host'];
if ($domain) {
$file = dr_catcher_data($img, 8);
if (!$file) {
CI_DEBUG(@反饋BUG) && log_message('debug', '服務(wù)器無法下載圖片:'.$img);
} else {
// 嘗試找一找附件庫(kù)
$att = \Phpcmf\Service::M()->table('attachment')->like('related', 'ueditor')->where('filemd5', md5($file))->getRow();
if ($att) {
$img = $att['id'];
} else {
// 下載歸檔
$rt = \Phpcmf\Service::L('upload')->down_file([
'url' => $img,
'timeout' => 5,
'watermark' => \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark', 'ueditor') || $field['setting']['option']['watermark'] ? 1 : 0,
'attachment' => \Phpcmf\Service::M('Attachment')->get_attach_info(intval($field['setting']['option']['attachment']), $field['setting']['option']['image_reduce']),
'file_ext' => $ext,
'file_content' => $file,
]);
if ($rt['code']) {
$att = \Phpcmf\Service::M('Attachment')->save_data($rt['data'], 'ueditor:'.$rid);
if ($att['code']) {
// 歸檔成功
$value = str_replace($img, $rt['data']['url'], $value);
$img = $att['code'];
// 標(biāo)記附件
\Phpcmf\Service::M('Attachment')->save_ueditor_aid($rid, $att['code']);
}
}
}
}
}
}
\Phpcmf\Service::L('Field')->data[$_field['thumb']['ismain']]['thumb'] = $_POST['data']['thumb'] = $img;
}
}
}
}
}
// 最后得到的文檔內(nèi)容
$save[0]['content'] = $value;
// 最后得到的縮略圖
$save[1]['thumb'] = $img;
$rt = $this->content_model->save_content(0, $save);
if ($rt['code'])
{
/*
// 用于發(fā)布成功后生成靜態(tài)文件代碼
//dr_html_auth($_SERVER['SERVER_ADDR']);
//dr_catcher_data(SITE_URL.'index.php?s='.MOD_DIR.'&c=html&m=showfile&id='.$rt['id']);
$atcode = 'chtml_'.SITE_ID.'_'.MOD_DIR.'_'.$rt['code'];
\Phpcmf\Service::L('cache')->set_auth_data($atcode, $rt['code'], SITE_ID);
dr_catcher_data(SITE_URL.'index.php?s='.MOD_DIR.'&c=html&m=showfile&id='.$rt['code'].'&atcode='.$atcode);
*/
exit('成功');
}
else
{
exit('失敗');
}
}
// 獲取遠(yuǎn)程附件擴(kuò)展名
function _get_image_ext($url) {
if (strlen($url) > 300) {
return '';
}
$arr = ['gif', 'jpg', 'jpeg', 'png', 'webp'];
$ext = str_replace('.', '', trim(strtolower(strrchr($url, '.')), '.'));
if ($ext && in_array($ext, $arr)) {
return $ext; // 滿足擴(kuò)展名
} elseif ($ext && strlen($ext) < 4) {
//CI_DEBUG(@反饋BUG) && log_message('error', '此路徑不是遠(yuǎn)程圖片:'.$url);
return ''; // 表示不是圖片擴(kuò)展名了
}
foreach ($arr as $t) {
if (stripos($url, $t) !== false) {
return $t;
}
}
$rt = getimagesize($url);
if ($rt && $rt['mime']) {
foreach ($arr as $t) {
if (stripos($rt['mime'], $t) !== false) {
return $t;
}
}
}
CI_DEBUG(@反饋BUG) && log_message('debug', '服務(wù)器無法獲取遠(yuǎn)程圖片的擴(kuò)展名:'.dr_safe_replace($url));
return '';
}
exit;
發(fā)布失敗,錯(cuò)誤信息:
網(wǎng)頁(yè)源代碼:
返回的Header:
HTTP/1.1 200 OK
Server:nginx/1.15.11
Date:Sat, 29 Jan 2022 18:31:00 GMT
Content-Type:text/html; charset=utf-8
Transfer-Encoding:chunked
Connection:keep-alive
X-Powered-By:PHP/7.3.4
Content-Length:6
看看看看?。。?br/>
學(xué)習(xí)一下
好人一聲平安
我要下載