1 wxml:

<view>
<form bindsubmit="dopost">
<view>
<label>真实姓名</label>
<input name="truename" value="{{ userinfo.truename }}" />
</view>
<view>
<label>身份证号</label>
<input name="card" type="idcard" value="{{ userinfo.card }}" />
</view>
<view class="tip-msg">
添加手持身份证照片
<text>(照片仅用于身份认证)</text>
</view>
<view class="uppic" bind:tap="upfile">
<text class="iconfont icon-jiahao"></text>
</view>
<view class="imglist">
<block wx:for="{{upfile}}" wx:key="upfile">
<image src="{{item}}" />
</block>
</view>
<view class="sendbtn">
提交信息
<button type="primary" form-type="submit">提交信息</button>
</view>
</form>
</view>

 2 wx.js:

    // pages/page/page.js
Page({
/**
* 页面的初始数据
*/
data: {
upfile:[]
},
//图片上传
upfile:function(res){
let that = this
let file = []
// 本地图片
wx.chooseImage({
count: 3,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success (res) {
// tempFilePath可以作为img标签的src属性显示图片
let tempFilePaths = res.tempFilePaths;
tempFilePaths.map(filepath=>{
wx.uploadFile({
// 发送的网址
url: 'http://www.yan.com/api/xcx/xcxImg',
filePath: filepath,
// 发送的文件
name: 'file',
success (ret){
let json = JSON.parse(ret.data)
// console.log(json)
// 将返回的文件追加至file空数组
file.push(json.data)
// 设置data数据中的file
that.setData({
upfile:file
})
},fail(res){
wx.showToast({
title: '请求失败',
icon:"error"
})
}
})
})
}
})
}, })

wxss

/* pages/page/page.wxss */
page {
background-color: #fff;
} .imglist image{
width: 200rpx;
height: 200rpx;
}
.tip {
background-color: #fff3cd;
height: 60rpx;
line-height: 60rpx;
font-size: 14px;
color: #fb6951;
padding-left: 10rpx;
}
.tip text:nth-of-type(1) {
margin-right: 10rpx;
}
form view {
padding: 30rpx;
display: flex;
height: 80rpx;
line-height: 80rpx;
border-bottom: 1px solid #eeeeee;
}
form view:nth-last-of-type(1){
border: none;
}
form view label {
margin-right: 30rpx;
}
form view input {
height: 80rpx;
line-height: 80rpx;
}
.tip-msg{
color: #a4a4a4;
}
.tip-msg text{
margin-left: 10rpx;
font-size: 12px;
}
.uppic{
margin-left: 10rpx;
margin-top: 10rpx;
width: 100rpx;
height: 100rpx;
border: 1px dashed #a4a4a4;
display: flex;
justify-content: center;
align-items: center;
} .sendbtn{
position: fixed;
bottom: 0px;
width: 750rpx;
height: 100rpx;
background: #21b97a;
padding: 0;
margin: 0;
text-align: center;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
font-size: 18px;
} .sendbtn button {
width: 100%;
height: 100rpx;
opacity: 0;
position: absolute;
top: 0;
}

3  laravel7  api.php书写路由                                                                                                                                                                                    

Route::group(['namespace'=>'xcx'],function (){

//图片
Route::post('xcx/xcxImg','LoginController@xcxImg'); });

4  然后composer下载七牛云

composer require itbdw/laravel-storage-qiniu

5 .打开 config 文件夹下的 app.php 文件,在 providers 中加入一下代码

itbdw\QiniuStorage\QiniuFilesystemServiceProvider::class,

6 .打开 config 文件夹下的 filesystems.php 文件,在 disks中加入一下代码,注意位置

'qiniu' => [
'driver' => 'qiniu',
'domain' => '', //你的七牛域名
'access_key'=> '', //AccessKey
'secret_key'=> '', //SecretKey
'bucket' => '', //Bucket名字,即七牛云存储空间名称
],

 'qiniu' => [
'driver' => 'qiniu',
'domain' => 'r3y7oifgb.hn-bkt.clouddn.com', //你的七牛域名
'access_key'=> '7Gu_5HzqSHJB3nLBz51pQN8oJBfqeGwd3kQ-vCNX', //AccessKey
'secret_key'=> 'frzqcOjOhL55eIMXQSLIfO_apMHrs0fr8jjklKDt', //SecretKey
'bucket' => 'yanbingexam', //Bucket名字,即七牛云存储空间名称
],

7 :控制器进行调用

  public function xcxImg(){
$disk = \Storage::disk('qiniu'); //使用七牛云上传
$time = date('Y-m-d');//文件上传时间
$filename = $disk->put($time, request()->file('file'));//上传 这里的image是前端的name值,自己来定
if(!$filename) {
return ['code' => 500, 'meg' => 'error', 'data' => []];
}
$img_url = $disk->getDriver()->downloadUrl($filename); //获取下载链接
return ['code' => 200, 'meg' => '上传成功', 'data' => $img_url];
}

8:七牛云进行查看,切记桶空间必须是公开的,要不上传不上去

参考:

(1)如果上传至本地图片参考以下代码:

 public function xcxImg(Request $request)
{
if ($request->hasFile('file')){
// 上传
$ret = $request->file('file')->store('', 'img');
$pic = '/uploads/img/' . $ret;
$disk =\Storage::disk('qiniu'); //使用七牛云上传
$time = date('Y-m-d');
$filename = $disk->put($time, request()->file('file'));//上传 这里的image是前端的name值,自己来定
if(!$filename) {
return ['code' => 500, 'meg' => 'error', 'data' => []];
}
$img_url = $disk->getDriver()->downloadUrl($filename); //获取下载链接
return ['code' => 200, 'meg' => '上传成功', 'data' => $img_url];
} }

(2) 如需将图片保存至本地参考以下博客

https://www.cnblogs.com/xiaoyantongxue/p/15679469.html

   public function store(Request $request)
{
//
$data = $request->post();
// 将文件上传至本地
$img = $request->file('img');
if (!empty($img)){
$img = "/".$request->file('img')->store(date('y/m/d')."/".'img');
$data['img'] = $img;
}
// 文件上传至七牛云
$disk = \Storage::disk('qiniu'); //使用七牛云上传
$time = date('Y-m-d');//文件上传时间
$filename = $disk->put($time, request()->file('img'));//上传 这里的image是前端的name值,自己来定
// 验证
$this->validate($request, ['name' => 'required', 'zhicheng' => 'required', 'img' => 'required'],
['name.required' => '医生姓名不可以为空', 'zhicheng.required' => '医生职称不可以为空', 'img.required' => '图片不可以为空']);
//添加入库
$res = Doctor::create($data);
if ($res) {
return redirect(route('doctor.index'))->with(['success' => '添加成功']);
}
return redirect(route('doctor.create'))->withErrors(['error' => '添加失败']);
}

 

                                        

微信小程序文件上传至七牛云(laravel7)的更多相关文章

  1. 微信小程序文件上传结合lin ul

    html <l-form name="goods" l-form-btn-class="l-form-btn-class" bind:linsubmit= ...

  2. .Net Core实现将文件上传到七牛云存储

    功能:将图片上传到七牛云存储 准备工作 注册七牛账号,提交实名认证(基本上1天内内审核通过) 登录七牛后台->对象存储->新建空间 (基本概念:https://developer.qini ...

  3. laravel7文件上传至七牛云并保存在本地图片

    HTML代码: <form class="layui-form" action="{{route('doctor.store')}}" method=&q ...

  4. 5行代码实现微信小程序图片上传与腾讯免费5G存储空间的使用

    本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率,同时也是微信小程序系列教程的视频 ...

  5. 快速高效实现微信小程序图片上传与腾讯免费5G存储空间的使用

    本文介绍了如何在微信小程序开发中使用腾讯官方提供的云开发功能快速实现图片的上传与存储,以及介绍云开发的 5G 存储空间的基本使用方法,这将大大提高微信小程序的开发效率 对于一般的图片上传功能开发,我们 ...

  6. 微信小程序图片上传并展示

    1.首先编写微信小程序的页面和样式: index.js var total = []; Page({ data: { perImgSrc: [] }, onLoad: function (option ...

  7. 小程序文件上传uploadFile

    前台代码: bindPhoto(e) { var that = this; wx.chooseImage({ count: 1, sizeType: ['original','compressed'] ...

  8. 微信小程序---图片上传+服务端接受

    原文地址:http://blog.csdn.net/sk719887916/article/details/54312573 微信小程序,图片上传,应用地方-修改用户信息的头像. 详细代码: 小程序的 ...

  9. 微信小程序图片上传和裁剪

    本篇博客用于解决微信小程序图片裁剪问题 图片裁剪常用于头像选择和图片合成等. 图片裁剪解决方案: 目前网络上知名的微信小程序图片裁剪插件是we-cropper(文末有链接) 操作步骤:下载好we-cr ...

随机推荐

  1. HTML 代码复用

    前言 通常我们所做的一些页面,我们可以从设计图里面看出有一些地方是相同的.例如:头部,底部,侧边栏等等.如果是制作静态页面的同学,对于这些重复的部分只能够通过复制粘贴到新的页面来,如果页面的数量上去了 ...

  2. [01-jwt]C# JWT基础知识详解

    本篇文章将介绍jwt基础概念性知识,不含实操代码展示,特别适合该方面知识空白的人群,大神级别请选择性观看.不喜禁喷,出门右转,谢谢配合. 一.什么是JWT? JWT是简写,全称是JSON Web To ...

  3. linux_4

    自建yum仓库,分别为网络源和本地源 编译安装http2.4 linux命令练习 列出ubuntu软件管理工具apt的一些用法(自由总结)

  4. Solution -「CF 156D」Clues

    \(\mathcal{Description}\)   link.   给一个 \(n\) 个点 \(m\) 条边的无向图 \(G\).设图上有 \(k\) 个连通块,求出添加 \(k-1\) 条边使 ...

  5. HashMap(1.8)源码学习

    一.HashMap介绍 1.哈希表(hash table) 在哈希表中进行添加,删除,查找等操作,时间复杂度为O(1) 存储位置 = f(关键字) 其中,这个函数f一般称为哈希函数,这个函数的设计好坏 ...

  6. 打造一款属于自己的CentOS操作系统

    文章目录 声明 关闭selinux以及firewalld 修改终端前缀显示 修改默认网卡名称为eth0 替换yum源 安装常用工具 优化history 配置回收站 迎宾显示 优化vim 清空yum缓存 ...

  7. suse 12 升级 OpenSSH-7.2p2 到 OpenSSH-8.4p1

    文章目录 1.查看当前当前环境信息 1.1.查看openssh当前版本 1.2.查看当前linux发行版 2.部署telnet-server 2.1.下载telnet-server 2.2.配置tel ...

  8. 性能测试:k8s集群监控环境搭建(kube-prometheus)

    选择kube-prometheus版本 k8s集群版本是1.22.x 5个节点 说明:如果你电脑配置低,也可以1个master节点,2个node节点 3个节点 Kube-Prometheus地址:ht ...

  9. [题解]第十一届北航程序设计竞赛预赛——I.神奇宝贝大师

    题目描述 一张n*m的地图,每个格子里面有一定数量的神奇宝贝,求一个最优位置,使得所有神奇宝贝到该位置的曼哈顿距离最小. 一共有T组数据,每组数据包含两行,第一行是n和m(1<=n,m<= ...

  10. EasyUI Datagrid 数据网格

    前端用easyUI开发时,官方给的文档指导太少,网上找的又很慢,因此,我总结了一个后台返回数据后,用easyUI生成表格的方法,可编辑可分页: 1 function paginationTable(i ...