TP5(thinkPHP5框架)基于bootstrap实现的单图上传插件用

编程学习 2021-07-04 23:05www.dzhlxh.cn编程入门
这篇文章主要介绍了TP5(thinkPHP5框架)基于bootstrap实现的单图上传插件用法,结合实例形式分析了thinkPHP5框架结合bootstrap实现图片上传相关布局与控制器操作技巧,需要的朋友可以参考下

本文实例讲述了TP5(thinkPHP5框架)基于bootstrap实现的单图上传插件用法。分享给大家供大家参考,具体如下:

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框架的PHP程序设计有所帮助。

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板