码迷,mamicode.com
首页 > 其他好文 > 详细

如何在laravel框架中使用阿里云的oos

时间:2020-04-30 13:37:00      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:mini   list   演示   color   sheet   ase   utf-8   height   aof   

推荐第三方扩展包:

packaglist地址1 github地址
链接 链接

1.执行comopser安装扩展包:

composer require johnlui/aliyun-oss

2.前端界面:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css"/>
    <script src="https://www.layuicdn.com/layui/layui.js"></script>
    <title>Document</title>
</head>
<body>
<div class="layui-upload">
    <button type="button" class="layui-btn" id="test1">上传图片</button>
    <div class="layui-upload-list">
        <img class="layui-upload-img" id="demo1" style="width: 200px;height: 100px">
        <p id="demoText"></p>
    </div>
</div>
</body>
<script>
    layui.use(‘upload‘, function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: ‘#test1‘,
            headers: {
                ‘X-CSRF-TOKEN‘: $(‘meta[name="csrf-token"]‘).attr(‘content‘)
            }
            , url: ‘upload‘ //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例,不支持ie8
                obj.preview(function (index, file, result) {
                    $(‘#demo1‘).attr(‘src‘, result); //图片链接(base64)
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg(‘上传失败‘);
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态,并实现重传
                var demoText = $(‘#demoText‘);
                demoText.html(‘<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>‘);
                demoText.find(‘.demo-reload‘).on(‘click‘, function () {
                    uploadInst.upload();
                });
            }
        });
    });
</script>
</html>

如何在laravel框架中使用阿里云的oos

标签:mini   list   演示   color   sheet   ase   utf-8   height   aof   

原文地址:https://www.cnblogs.com/yaoliuyang/p/12808157.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!