jquery 按钮预览图片功能的代码,我看不太懂。应该怎么学

Original 2019-03-04 21:20:07 296
abstract:



namespace app\admin\controller;


use app\admin\controller\Common;

use app\admin\model\NewsModel;

use app\admin\model\NewsPicModel;

use think\facade\Request;

use think\facade\Session;


class NewsPic extends Common

{

public function index()

{

//实例化模型

$newPic = new NewsPicModel();

$pics = $newPic->order('id', 'desc')->paginate(6);

$this->view->pics = $pics;

// 渲染新闻缩略图列表

return $this->fetch();

}


public function add()

{

// 查询所有新闻数据

$news = NewsModel::all();

//将数据赋值给模板

$this->view->news = $news;

// 渲染新闻缩略图添加界面

return $this->fetch();

}


public function upload()

{

// 获取上传图片的信息

$file = Request::file('file');

// 验证图片并移动到指定目录

if ($info = $file->validate(['ext' => 'jpg,jpeg,png,gif'])->move('upload')) {

// 拼接图片路径

$fileName = '/upload/' . $info->getSaveName();

// 返回上传成功的提示信息

return json([1, '上传成功!', 'data' => $fileName]);

} else {

// 返回上传失败的错误信息

return $file->getError();

}


}


public function DoAdd()

{

// 获取提交的数据

$data = Request::param();

$data['time'] = time();

$data['username'] = Session::get('username');

$newPic = new NewsPicModel();

if ($newPic->save($data)) {

return ['res' => 1, 'msg' => '发布成功!'];

} else {

return ['res' => 0, 'msg' => '发布失败!'];

}

}


public function del()

{

$picId=Request::param('id');

$newPic = new NewsPicModel();

if ($newPic->destroy($picId)){

return ['res'=>1];

}

}

}


Correcting teacher:查无此人Correction time:2019-03-05 09:11:51
Teacher's summary:完成的不错。jQuery按钮预览,使用插件,自己写也可以。如果觉得看不懂,就把别人写好的,一个一个函数去查询。继续加油

Release Notes

Popular Entries