laravel :上传图片+上传语音+上传视频+获取验证码(阿里大鱼)+验证码登录

<?php


namespace App\Http\Controllers;


use App\Models\Opinion;
use App\Models\Shops;
use App\Models\ShopSchool;
use App\Models\Updated;
use App\Models\User;
use Cache;
use Carbon\Carbon;
use Illuminate\Http\Request;
use PhpSms;
use Storage;


class CommonController extends Controller
{
    public function uploadImage(Request $request)
    {
        if ($request->hasFile('upfile')) {
            $file = $request->file('upfile');
            $allowed_extensions = ['png', 'jpg', 'gif'];
            if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
                return ['error' => 'You may only upload png, jpg or gif.'];
            }
            $baseName =md5(time().str_random(10).uniqid());
            $newName = $baseName.'.'.$file->getClientOriginalExtension();
            $saveDir = 'upload/'.date('Y').'/'.date('m').'/'.date('d').'/';
            $savePath = $saveDir.$newName;
            $bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
            if (Storage::exists($savePath)) return response()->json(['code'=>200,'msg'=>'上传成功','data'=>['uri'=>$savePath]]);


        }
        return response()->json(['code'=>500,'msg'=>'上传失败']);
    }

//图片修改
    public function postEditorUpload(Request $request)
    {
        if ($request->hasFile('upfile')) {
            $file = $request->file('upfile');
            $allowed_extensions = ['png', 'jpg', 'gif'];
            if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
                return ['error' => 'You may only upload png, jpg or gif.'];
            }
            $baseName =md5(time().str_random(10).uniqid()).'.'.$file->getClientOriginalExtension();
            $newName = $baseName;
            $saveDir = 'uploads/'.date('Y').'/'.date('m').'/'.date('d').'/';
            $savePath = $saveDir.$newName;
//            $bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
            $bytes = Storage::put($savePath, file_get_contents($file->getRealPath()));
            $size = Storage::size($savePath);
            $url = $savePath;
            if (Storage::e
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值