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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-04-03 我要评论

本文实例讲述了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框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们