TP5 of thinkPHP5 Framework Usage Example of Single Graph Upload Plug in Based on bootstrap Implementation

  • 2021-12-11 17:26:41
  • OfStack

This article illustrates the usage of TP5 (thinkPHP5 framework) single graph upload plug-in based on bootstrap. Share it for your reference, as follows:

1-Introducing js files and css files


<!-- Picture upload -->
<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 code


<div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label"> Carousel chart </label>
  <div class="col-sm-10">
    <input class="file" type="file" name="img">
  </div>
</div>

3-Controller


public function add() {
 $file = $request->file("img");
// Declaration 1 Empty file path 
$imgPath = "";
// Move files to the framework to apply more directories 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 {
  // Error prompt user 
  return $this->error($file->getError());
    }
// Assignment 
$data["thumb_url"] = $imgPath;
$dataId = Db::name('top_bar')->insertGetId($data);
}

Additional features and plug-ins can be found at: https://www.kancloud.cn/he_he/thinkphp5/787173

Readers who are interested in thinkPHP can check the topics of this site: "ThinkPHP Introduction Tutorial", "thinkPHP Template Operation Skills Summary", "ThinkPHP Common Methods Summary", "codeigniter Introduction Tutorial", "CI (CodeIgniter) Framework Advanced Tutorial", "Zend FrameWork Framework Introduction Tutorial" and "PHP Template Technology Summary".

Hope that this article is based on the framework of ThinkPHP PHP programming help.


Related articles: