TP5(thinkPHP5框架)基于bootstrap實(shí)現(xiàn)的單圖上傳插件用法示例
本文實(shí)例講述了TP5(thinkPHP5框架)基于bootstrap實(shí)現(xiàn)的單圖上傳插件用法。分享給大家供大家參考,具體如下:
1-引入js文件和css文件
<!--圖片上傳--> <link href="/public/static/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet"> <link href="/public/static/css/fileinput.css" rel="external nofollow" media="all" rel="stylesheet" type="text/css" /> <script src="/public/static/js/jquery-2.0.3.min.js"></script> <script src="/public/static/js/fileinput.js" type="text/javascript"></script> <script src="/public/static/js/fileinput_locale_de.js" type="text/javascript"></script> <script src="/public/static/js/bootstrap.min.js" type="text/javascript"></script>
2-html代碼
<div class="form-group"> <label for="inputPassword3" class="col-sm-2 control-label">輪播圖</label> <div class="col-sm-10"> <input class="file" type="file" name="img"> </div> </div>
3-控制器
public function add() { $file = $request->file("img"); //聲明一個(gè)空的文件路徑 $imgPath = ""; //移動(dòng)文件到框架應(yīng)用更目錄的public/uploads/ if ($file) { $info = $file->move(ROOT_PATH . 'public' . DS . 'upload' . DS . 'top_bar' . DS . date('Y') . DS . date('m-d'),md5(microtime(true))); if ($info) { $imgPath = "/public/upload/top_bar/" . date('Y') . '/' . date('m-d') . '/' . $info->getSaveName(); } } else { //錯(cuò)誤提示用戶 return $this->error($file->getError()); } //賦值 $data["thumb_url"] = $imgPath; $dataId = Db::name('top_bar')->insertGetId($data); }
更多的功能和插件 參考地址:https://www.kancloud.cn/he_he/thinkphp5/787173
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php獲取數(shù)據(jù)庫中數(shù)據(jù)的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄猵hp獲取數(shù)據(jù)庫中數(shù)據(jù)的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06CakePHP框架Model關(guān)聯(lián)對象用法分析
這篇文章主要介紹了CakePHP框架Model關(guān)聯(lián)對象用法,結(jié)合實(shí)例形式分析了cakePHP框架Model關(guān)聯(lián)對象的功能、定義及具體使用方法,需要的朋友可以參考下2017-08-08thinkphp5?操作redis?實(shí)現(xiàn)文章的熱度排行和點(diǎn)贊排行的示例
本文主要介紹了thinkphp5?操作redis?實(shí)現(xiàn)文章的熱度排行和點(diǎn)贊排行的示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04Symfony頁面的基本創(chuàng)建實(shí)例詳解
這篇文章主要介紹了Symfony頁面的基本創(chuàng)建實(shí)例詳解,詳細(xì)分析了Symfony頁面的具體創(chuàng)建流程與注意事項(xiàng),需要的朋友可以參考下2015-01-01PHP文件緩存smarty模板應(yīng)用實(shí)例分析
這篇文章主要介紹了PHP文件緩存smarty模板應(yīng)用方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了smarty模板緩存的相關(guān)使用技巧,需要的朋友可以參考下2016-02-02PHP計(jì)算一年多少個(gè)星期和每周的開始和結(jié)束日期
這篇文章主要介紹了PHP計(jì)算每周的開始和結(jié)束日期,php實(shí)現(xiàn)計(jì)算一年多少周,同時(shí)計(jì)算出每一周的開始日期和結(jié)束日期,需要的朋友可以參考下2014-07-07