TP5(thinkPHP5框架)基于bootstrap實現(xiàn)的單圖上傳插件用法示例
本文實例講述了TP5(thinkPHP5框架)基于bootstrap實現(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");
//聲明一個空的文件路徑
$imgPath = "";
//移動文件到框架應用更目錄的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 {
//錯誤提示用戶
return $this->error($file->getError());
}
//賦值
$data["thumb_url"] = $imgPath;
$dataId = Db::name('top_bar')->insertGetId($data);
}
更多的功能和插件 參考地址:https://www.kancloud.cn/he_he/thinkphp5/787173
更多關于thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。
相關文章
php獲取數(shù)據(jù)庫中數(shù)據(jù)的實現(xiàn)方法
下面小編就為大家?guī)硪黄猵hp獲取數(shù)據(jù)庫中數(shù)據(jù)的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-06-06
thinkphp5?操作redis?實現(xiàn)文章的熱度排行和點贊排行的示例
本文主要介紹了thinkphp5?操作redis?實現(xiàn)文章的熱度排行和點贊排行的示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-04-04

