原创文章转自:https://www.ympfb.com/show-30-24-1.html
tp5 thinkphp
给大家分享一个图片上传的方法 ,直接可以用的
带 前台 和 控制器 的源码
前台
<div class="form-group"> </div>
<div> <label class="col-sm-3 control-label no-padding-right"> 上传图片 </label></div>
<div class="col-sm-3 file-loading"> </div>
<div><input class="file" data-min-file-count="2" data-overwrite-initial="false" id="file-1" multiple="multiple" name="pathImg[]" type="file" /></div>
</div>
<div>
这里面有样式,是bootstrop 的样式,如果不需要就直接去掉,加自己的样式就可以了
控制器
public function add() {
$data = input('post.');
$arryFile = request()->file("pathImg");
foreach ($arryFile as $File){
$pathImg="";
//移动文件到框架应用更目录的public/uploads/
$info = $File->move(ROOT_PATH . 'public' . DS . 'upload' . DS . 'top_bar' . DS . date('Y') . DS . date('m-d'),md5(microtime(true)));
if ($info) {
$pathImg = "/upload/top_bar/" . date('Y') . '/' . date('m-d') . '/' . $info->getFilename();
} else {
//错误提示用户
return $this->error($File->getError());
}
$result["pathImg"] = $pathImg;
$result["name"] = $data["name"];
$result["images_team"] = $data["images_team"];
$result["images_tag"] = $data["images_tag"];
Db('images')->insert($result);
}
这是 单张图片上传, 下次给大家分享 多张图片上传