上次整合缩略图,结果忘记发出来了。群里的朋友提起我才想起来我没发出来。
先上效果图。

,具体的话可以参考我的博客的效果图。
,首先在源码中的 App/Common/Common/function.php中添加
// 生成缩略图
function thumbImg($str){
preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $str, $img);
if($img[0][0]){
$src = substr($img[0][0],5,-1);
$image = new \Think\Image();
$image->open('.'.$src);
$name = time();
$image->thumb(150, 120)->save('./uploads/Thumb/'.$name.'.jpg');
$url = '/uploads/Thumb/'.$name.'.jpg';
return $url;
}else{
return flase;
}
}然后在 User/Controller/ArticleController.class.php修改addArticleHandle
public function addArticleHandle(){
// 发表文章表单操作
$url = thumbImg($_POST['a_content']);
$data = array (
'a_title' => I('post.a_title'),
'pid' => I('post.pid'),
'a_url' => $url,
'a_keyword' => I('post.a_keyword'),
'a_remark' => I('post.a_remark'),
'a_content' => $_POST['a_content'],
'a_from'=> getOS(),
'a_view' => I('post.a_view'),
'a_hit' => I('post.a_hit'),
'a_writer' => I('post.a_writer'),
'a_time' => time(),
'a_ip' => get_client_ip(),
);
if(D('Article')->addArticle($data)){
$this->success('发表文章完成!转调到文章列表','articleList');
}else{
$this->error('发表文章失败!');
}
}如果本地测试,出现无效路径等请修改
$image->open($src);
如果有其他问题,请在群和博客中留言,谢谢。
上一篇: 武汉天气10大神定律...
下一篇: JQ获取兄弟元素的值...