亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jquery 按鈕預(yù)覽圖片功能的代碼,我看不太懂。應(yīng)該怎么學(xué)

原創(chuàng) 2019-03-04 21:20:07 307
摘要:<?phpnamespace 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 ex

<?php



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()

    {

        //實(shí)例化模型

        $newPic = new NewsPicModel();

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

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

        // 渲染新聞縮略圖列表

        return $this->fetch();

    }


    public function add()

    {

        // 查詢所有新聞數(shù)據(jù)

        $news = NewsModel::all();

        //將數(shù)據(jù)賦值給模板

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

        // 渲染新聞縮略圖添加界面

        return $this->fetch();

    }


    public function upload()

    {

        // 獲取上傳圖片的信息

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

        // 驗(yàn)證圖片并移動(dòng)到指定目錄

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

            // 拼接圖片路徑

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

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

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

        } else {

            // 返回上傳失敗的錯(cuò)誤信息

            return $file->getError();

        }


    }


    public function DoAdd()

    {

        // 獲取提交的數(shù)據(jù)

        $data = Request::param();

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

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

        $newPic = new NewsPicModel();

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

            return ['res' => 1, 'msg' => '發(fā)布成功!'];

        } else {

            return ['res' => 0, 'msg' => '發(fā)布失??!'];

        }

    }


    public function del()

    {

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

        $newPic = new NewsPicModel();

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

            return ['res'=>1];

        }

    }

}


批改老師:查無此人批改時(shí)間:2019-03-05 09:11:51
老師總結(jié):完成的不錯(cuò)。jQuery按鈕預(yù)覽,使用插件,自己寫也可以。如果覺得看不懂,就把別人寫好的,一個(gè)一個(gè)函數(shù)去查詢。繼續(xù)加油

發(fā)佈手記

熱門詞條